Trismegiste\Mondrian\Visitor\VisitorGateway::pushState PHP Méthode

pushState() public méthode

public pushState ( $stateKey, PhpParser\Node $node )
$node PhpParser\Node
    public function pushState($stateKey, Node $node)
    {
        if ($this->debug) {
            printf("Stacking %s %s %s %d\n", $stateKey, $node->getType(), $node->name, count($this->stateStack));
        }
        $state = $this->getState($stateKey);
        array_unshift($this->stateStack, ['node' => $node, 'state' => $state, 'key' => $state->getName(), 'nodeType' => $node->getType()]);
    }

Usage Example

 public function testPushState()
 {
     $listing = [$this->getMockState('one'), $this->getMockState('two'), $this->getMockState('three')];
     $this->buildVisitor($listing);
     $node = [$this->getMock('PhpParser\\Node'), $this->getMock('PhpParser\\Node'), $this->getMock('PhpParser\\Node')];
     $this->assertNull($this->sut->getNodeFor('one'));
     $this->sut->pushState('two', $node[0]);
     $this->assertNull($this->sut->getNodeFor('one'));
     $this->assertEquals($node[0], $this->sut->getNodeFor('two'));
     $this->sut->pushState('three', $node[1]);
     $this->assertNull($this->sut->getNodeFor('one'));
     $this->assertEquals($node[0], $this->sut->getNodeFor('two'));
     $this->assertEquals($node[1], $this->sut->getNodeFor('three'));
     $this->sut->leaveNode($node[1]);
     $this->assertNull($this->sut->getNodeFor('one'));
     $this->assertEquals($node[0], $this->sut->getNodeFor('two'));
     $this->assertAttributeCount(2, 'stateStack', $this->sut);
     $this->sut->leaveNode($node[0]);
     $this->assertAttributeCount(1, 'stateStack', $this->sut);
 }