Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / nikic / php-parser / test / PhpParser / NodeTraverserTest.php
index 61c8e25bb08e19269d7ddcdbafca14a70cde0bfa..4818457a9b7eca85e830ec499915fca881d3ffdd 100644 (file)
@@ -117,11 +117,9 @@ class NodeTraverserTest extends TestCase
         );
     }
 
-    /**
-     * @expectedException \LogicException
-     * @expectedExceptionMessage Invalid node structure: Contains nested arrays
-     */
     public function testInvalidDeepArray() {
+        $this->expectException(\LogicException::class);
+        $this->expectExceptionMessage('Invalid node structure: Contains nested arrays');
         $strNode = new String_('Foo');
         $stmts = [[[$strNode]]];
 
@@ -167,6 +165,42 @@ class NodeTraverserTest extends TestCase
         $this->assertEquals($stmts, $traverser->traverse($stmts));
     }
 
+    public function testDontTraverseCurrentAndChildren() {
+        // print 'str'; -($foo * $foo);
+        $strNode = new String_('str');
+        $printNode = new Expr\Print_($strNode);
+        $varNode = new Expr\Variable('foo');
+        $mulNode = new Expr\BinaryOp\Mul($varNode, $varNode);
+        $divNode = new Expr\BinaryOp\Div($varNode, $varNode);
+        $negNode = new Expr\UnaryMinus($mulNode);
+        $stmts = [$printNode, $negNode];
+
+        $visitor1 = $this->getMockBuilder(NodeVisitor::class)->getMock();
+        $visitor2 = $this->getMockBuilder(NodeVisitor::class)->getMock();
+
+        $visitor1->expects($this->at(1))->method('enterNode')->with($printNode)
+            ->will($this->returnValue(NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN));
+        $visitor1->expects($this->at(2))->method('leaveNode')->with($printNode);
+
+        $visitor1->expects($this->at(3))->method('enterNode')->with($negNode);
+        $visitor2->expects($this->at(1))->method('enterNode')->with($negNode);
+
+        $visitor1->expects($this->at(4))->method('enterNode')->with($mulNode)
+            ->will($this->returnValue(NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN));
+        $visitor1->expects($this->at(5))->method('leaveNode')->with($mulNode)->willReturn($divNode);
+
+        $visitor1->expects($this->at(6))->method('leaveNode')->with($negNode);
+        $visitor2->expects($this->at(2))->method('leaveNode')->with($negNode);
+
+        $traverser = new NodeTraverser;
+        $traverser->addVisitor($visitor1);
+        $traverser->addVisitor($visitor2);
+
+        $resultStmts = $traverser->traverse($stmts);
+
+        $this->assertInstanceOf(Expr\BinaryOp\Div::class, $resultStmts[1]->expr);
+    }
+
     public function testStopTraversal() {
         $varNode1 = new Expr\Variable('a');
         $varNode2 = new Expr\Variable('b');