X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FNodeFinderTest.php;fp=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FNodeFinderTest.php;h=daf42729a6df127c1344d707f17fa66c6d6bcb4b;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/vendor/nikic/php-parser/test/PhpParser/NodeFinderTest.php b/vendor/nikic/php-parser/test/PhpParser/NodeFinderTest.php new file mode 100644 index 000000000..daf42729a --- /dev/null +++ b/vendor/nikic/php-parser/test/PhpParser/NodeFinderTest.php @@ -0,0 +1,60 @@ +var, $assign->expr->left, $assign->expr->right]; + return [$stmts, $vars]; + } + + public function testFind() { + $finder = new NodeFinder; + list($stmts, $vars) = $this->getStmtsAndVars(); + $varFilter = function(Node $node) { + return $node instanceof Expr\Variable; + }; + $this->assertSame($vars, $finder->find($stmts, $varFilter)); + $this->assertSame($vars, $finder->find($stmts[0], $varFilter)); + + $noneFilter = function () { return false; }; + $this->assertSame([], $finder->find($stmts, $noneFilter)); + } + + public function testFindInstanceOf() { + $finder = new NodeFinder; + list($stmts, $vars) = $this->getStmtsAndVars(); + $this->assertSame($vars, $finder->findInstanceOf($stmts, Expr\Variable::class)); + $this->assertSame($vars, $finder->findInstanceOf($stmts[0], Expr\Variable::class)); + $this->assertSame([], $finder->findInstanceOf($stmts, Expr\BinaryOp\Mul::class)); + } + + public function testFindFirst() { + $finder = new NodeFinder; + list($stmts, $vars) = $this->getStmtsAndVars(); + $varFilter = function(Node $node) { + return $node instanceof Expr\Variable; + }; + $this->assertSame($vars[0], $finder->findFirst($stmts, $varFilter)); + $this->assertSame($vars[0], $finder->findFirst($stmts[0], $varFilter)); + + $noneFilter = function () { return false; }; + $this->assertNull($finder->findFirst($stmts, $noneFilter)); + } + + public function testFindFirstInstanceOf() { + $finder = new NodeFinder; + list($stmts, $vars) = $this->getStmtsAndVars(); + $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts, Expr\Variable::class)); + $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts[0], Expr\Variable::class)); + $this->assertNull($finder->findFirstInstanceOf($stmts, Expr\BinaryOp\Mul::class)); + } +}