comparison vendor/nikic/php-parser/test/PhpParser/NodeVisitor/FirstFindingVisitorTest.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 c2387f117808
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 FirstFindingVisitorTest extends TestCase
11 {
12 public function testFindFirstVariable() {
13 $traverser = new NodeTraverser();
14 $visitor = new FirstFindingVisitor(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\Variable('b'));
20 $stmts = [new Node\Stmt\Expression($assign)];
21
22 $traverser->traverse($stmts);
23 $this->assertSame($assign->var, $visitor->getFoundNode());
24 }
25
26 public function testFindNone() {
27 $traverser = new NodeTraverser();
28 $visitor = new FirstFindingVisitor(function(Node $node) {
29 return $node instanceof Node\Expr\BinaryOp;
30 });
31 $traverser->addVisitor($visitor);
32
33 $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
34 $stmts = [new Node\Stmt\Expression($assign)];
35
36 $traverser->traverse($stmts);
37 $this->assertSame(null, $visitor->getFoundNode());
38 }
39 }