comparison vendor/nikic/php-parser/test/PhpParser/NodeVisitor/FindingVisitorTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\NodeVisitor;
4
5 use PhpParser\Node;
6 use PhpParser\Node\Expr;
7 use PhpParser\NodeTraverser;
8 use PHPUnit\Framework\TestCase;
9
10 class FindingVisitorTest extends TestCase
11 {
12 public function testFindVariables() {
13 $traverser = new NodeTraverser();
14 $visitor = new FindingVisitor(function(Node $node) {
15 return $node instanceof Node\Expr\Variable;
16 });
17 $traverser->addVisitor($visitor);
18
19 $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat(
20 new Expr\Variable('b'), new Expr\Variable('c')
21 ));
22 $stmts = [new Node\Stmt\Expression($assign)];
23
24 $traverser->traverse($stmts);
25 $this->assertSame([
26 $assign->var,
27 $assign->expr->left,
28 $assign->expr->right,
29 ], $visitor->getFoundNodes());
30 }
31
32 public function testFindAll() {
33 $traverser = new NodeTraverser();
34 $visitor = new FindingVisitor(function(Node $node) {
35 return true; // All nodes
36 });
37 $traverser->addVisitor($visitor);
38
39 $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat(
40 new Expr\Variable('b'), new Expr\Variable('c')
41 ));
42 $stmts = [new Node\Stmt\Expression($assign)];
43
44 $traverser->traverse($stmts);
45 $this->assertSame([
46 $stmts[0],
47 $assign,
48 $assign->var,
49 $assign->expr,
50 $assign->expr->left,
51 $assign->expr->right,
52 ], $visitor->getFoundNodes());
53 }
54 }