comparison vendor/nikic/php-parser/test/PhpParser/NodeFinderTest.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;
4
5 use PhpParser\Node\Expr;
6 use PHPUnit\Framework\TestCase;
7
8 class NodeFinderTest extends TestCase
9 {
10 private function getStmtsAndVars() {
11 $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat(
12 new Expr\Variable('b'), new Expr\Variable('c')
13 ));
14 $stmts = [new Node\Stmt\Expression($assign)];
15 $vars = [$assign->var, $assign->expr->left, $assign->expr->right];
16 return [$stmts, $vars];
17 }
18
19 public function testFind() {
20 $finder = new NodeFinder;
21 list($stmts, $vars) = $this->getStmtsAndVars();
22 $varFilter = function(Node $node) {
23 return $node instanceof Expr\Variable;
24 };
25 $this->assertSame($vars, $finder->find($stmts, $varFilter));
26 $this->assertSame($vars, $finder->find($stmts[0], $varFilter));
27
28 $noneFilter = function () { return false; };
29 $this->assertSame([], $finder->find($stmts, $noneFilter));
30 }
31
32 public function testFindInstanceOf() {
33 $finder = new NodeFinder;
34 list($stmts, $vars) = $this->getStmtsAndVars();
35 $this->assertSame($vars, $finder->findInstanceOf($stmts, Expr\Variable::class));
36 $this->assertSame($vars, $finder->findInstanceOf($stmts[0], Expr\Variable::class));
37 $this->assertSame([], $finder->findInstanceOf($stmts, Expr\BinaryOp\Mul::class));
38 }
39
40 public function testFindFirst() {
41 $finder = new NodeFinder;
42 list($stmts, $vars) = $this->getStmtsAndVars();
43 $varFilter = function(Node $node) {
44 return $node instanceof Expr\Variable;
45 };
46 $this->assertSame($vars[0], $finder->findFirst($stmts, $varFilter));
47 $this->assertSame($vars[0], $finder->findFirst($stmts[0], $varFilter));
48
49 $noneFilter = function () { return false; };
50 $this->assertNull($finder->findFirst($stmts, $noneFilter));
51 }
52
53 public function testFindFirstInstanceOf() {
54 $finder = new NodeFinder;
55 list($stmts, $vars) = $this->getStmtsAndVars();
56 $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts, Expr\Variable::class));
57 $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts[0], Expr\Variable::class));
58 $this->assertNull($finder->findFirstInstanceOf($stmts, Expr\BinaryOp\Mul::class));
59 }
60 }