Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/Builder/FunctionTest.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 | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | 1 <?php declare(strict_types=1); |
2 | 2 |
3 namespace PhpParser\Builder; | 3 namespace PhpParser\Builder; |
4 | 4 |
5 use PhpParser\Comment; | 5 use PhpParser\Comment; |
6 use PhpParser\Node; | 6 use PhpParser\Node; |
7 use PhpParser\Node\Expr\Print_; | 7 use PhpParser\Node\Expr\Print_; |
8 use PhpParser\Node\Expr\Variable; | |
8 use PhpParser\Node\Scalar\String_; | 9 use PhpParser\Node\Scalar\String_; |
9 use PhpParser\Node\Stmt; | 10 use PhpParser\Node\Stmt; |
11 use PHPUnit\Framework\TestCase; | |
10 | 12 |
11 class FunctionTest extends \PHPUnit_Framework_TestCase | 13 class FunctionTest extends TestCase |
12 { | 14 { |
13 public function createFunctionBuilder($name) { | 15 public function createFunctionBuilder($name) { |
14 return new Function_($name); | 16 return new Function_($name); |
15 } | 17 } |
16 | 18 |
19 ->makeReturnByRef() | 21 ->makeReturnByRef() |
20 ->getNode() | 22 ->getNode() |
21 ; | 23 ; |
22 | 24 |
23 $this->assertEquals( | 25 $this->assertEquals( |
24 new Stmt\Function_('test', array( | 26 new Stmt\Function_('test', [ |
25 'byRef' => true | 27 'byRef' => true |
26 )), | 28 ]), |
27 $node | 29 $node |
28 ); | 30 ); |
29 } | 31 } |
30 | 32 |
31 public function testParams() { | 33 public function testParams() { |
32 $param1 = new Node\Param('test1'); | 34 $param1 = new Node\Param(new Variable('test1')); |
33 $param2 = new Node\Param('test2'); | 35 $param2 = new Node\Param(new Variable('test2')); |
34 $param3 = new Node\Param('test3'); | 36 $param3 = new Node\Param(new Variable('test3')); |
35 | 37 |
36 $node = $this->createFunctionBuilder('test') | 38 $node = $this->createFunctionBuilder('test') |
37 ->addParam($param1) | 39 ->addParam($param1) |
38 ->addParams(array($param2, $param3)) | 40 ->addParams([$param2, $param3]) |
39 ->getNode() | 41 ->getNode() |
40 ; | 42 ; |
41 | 43 |
42 $this->assertEquals( | 44 $this->assertEquals( |
43 new Stmt\Function_('test', array( | 45 new Stmt\Function_('test', [ |
44 'params' => array($param1, $param2, $param3) | 46 'params' => [$param1, $param2, $param3] |
45 )), | 47 ]), |
46 $node | 48 $node |
47 ); | 49 ); |
48 } | 50 } |
49 | 51 |
50 public function testStmts() { | 52 public function testStmts() { |
52 $stmt2 = new Print_(new String_('test2')); | 54 $stmt2 = new Print_(new String_('test2')); |
53 $stmt3 = new Print_(new String_('test3')); | 55 $stmt3 = new Print_(new String_('test3')); |
54 | 56 |
55 $node = $this->createFunctionBuilder('test') | 57 $node = $this->createFunctionBuilder('test') |
56 ->addStmt($stmt1) | 58 ->addStmt($stmt1) |
57 ->addStmts(array($stmt2, $stmt3)) | 59 ->addStmts([$stmt2, $stmt3]) |
58 ->getNode() | 60 ->getNode() |
59 ; | 61 ; |
60 | 62 |
61 $this->assertEquals( | 63 $this->assertEquals( |
62 new Stmt\Function_('test', array( | 64 new Stmt\Function_('test', [ |
63 'stmts' => array($stmt1, $stmt2, $stmt3) | 65 'stmts' => [ |
64 )), | 66 new Stmt\Expression($stmt1), |
67 new Stmt\Expression($stmt2), | |
68 new Stmt\Expression($stmt3), | |
69 ] | |
70 ]), | |
65 $node | 71 $node |
66 ); | 72 ); |
67 } | 73 } |
68 | 74 |
69 public function testDocComment() { | 75 public function testDocComment() { |
70 $node = $this->createFunctionBuilder('test') | 76 $node = $this->createFunctionBuilder('test') |
71 ->setDocComment('/** Test */') | 77 ->setDocComment('/** Test */') |
72 ->getNode(); | 78 ->getNode(); |
73 | 79 |
74 $this->assertEquals(new Stmt\Function_('test', array(), array( | 80 $this->assertEquals(new Stmt\Function_('test', [], [ |
75 'comments' => array(new Comment\Doc('/** Test */')) | 81 'comments' => [new Comment\Doc('/** Test */')] |
76 )), $node); | 82 ]), $node); |
77 } | 83 } |
78 | 84 |
79 public function testReturnType() { | 85 public function testReturnType() { |
80 $node = $this->createFunctionBuilder('test') | 86 $node = $this->createFunctionBuilder('test') |
81 ->setReturnType('void') | 87 ->setReturnType('void') |
82 ->getNode(); | 88 ->getNode(); |
83 | 89 |
84 $this->assertEquals(new Stmt\Function_('test', array( | 90 $this->assertEquals(new Stmt\Function_('test', [ |
85 'returnType' => 'void' | 91 'returnType' => 'void' |
86 ), array()), $node); | 92 ], []), $node); |
87 } | 93 } |
88 | 94 |
89 /** | 95 /** |
90 * @expectedException \LogicException | 96 * @expectedException \LogicException |
91 * @expectedExceptionMessage void type cannot be nullable | 97 * @expectedExceptionMessage void type cannot be nullable |
101 public function testInvalidParamError() { | 107 public function testInvalidParamError() { |
102 $this->createFunctionBuilder('test') | 108 $this->createFunctionBuilder('test') |
103 ->addParam(new Node\Name('foo')) | 109 ->addParam(new Node\Name('foo')) |
104 ; | 110 ; |
105 } | 111 } |
112 | |
113 /** | |
114 * @expectedException \LogicException | |
115 * @expectedExceptionMessage Expected statement or expression node | |
116 */ | |
117 public function testAddNonStmt() { | |
118 $this->createFunctionBuilder('test') | |
119 ->addStmt(new Node\Name('Test')); | |
120 } | |
106 } | 121 } |