var, $assign->expr->left, $assign->expr->right]; return [$stmts, $vars]; } public function testFind(): void { $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(): void { $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(): void { $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(): void { $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)); } }