Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/Builder/MethodTest.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 MethodTest extends \PHPUnit_Framework_TestCase | 13 class MethodTest extends TestCase |
12 { | 14 { |
13 public function createMethodBuilder($name) { | 15 public function createMethodBuilder($name) { |
14 return new Method($name); | 16 return new Method($name); |
15 } | 17 } |
16 | 18 |
21 ->makeStatic() | 23 ->makeStatic() |
22 ->getNode() | 24 ->getNode() |
23 ; | 25 ; |
24 | 26 |
25 $this->assertEquals( | 27 $this->assertEquals( |
26 new Stmt\ClassMethod('test', array( | 28 new Stmt\ClassMethod('test', [ |
27 'flags' => Stmt\Class_::MODIFIER_PUBLIC | 29 'flags' => Stmt\Class_::MODIFIER_PUBLIC |
28 | Stmt\Class_::MODIFIER_ABSTRACT | 30 | Stmt\Class_::MODIFIER_ABSTRACT |
29 | Stmt\Class_::MODIFIER_STATIC, | 31 | Stmt\Class_::MODIFIER_STATIC, |
30 'stmts' => null, | 32 'stmts' => null, |
31 )), | 33 ]), |
32 $node | 34 $node |
33 ); | 35 ); |
34 | 36 |
35 $node = $this->createMethodBuilder('test') | 37 $node = $this->createMethodBuilder('test') |
36 ->makeProtected() | 38 ->makeProtected() |
37 ->makeFinal() | 39 ->makeFinal() |
38 ->getNode() | 40 ->getNode() |
39 ; | 41 ; |
40 | 42 |
41 $this->assertEquals( | 43 $this->assertEquals( |
42 new Stmt\ClassMethod('test', array( | 44 new Stmt\ClassMethod('test', [ |
43 'flags' => Stmt\Class_::MODIFIER_PROTECTED | 45 'flags' => Stmt\Class_::MODIFIER_PROTECTED |
44 | Stmt\Class_::MODIFIER_FINAL | 46 | Stmt\Class_::MODIFIER_FINAL |
45 )), | 47 ]), |
46 $node | 48 $node |
47 ); | 49 ); |
48 | 50 |
49 $node = $this->createMethodBuilder('test') | 51 $node = $this->createMethodBuilder('test') |
50 ->makePrivate() | 52 ->makePrivate() |
51 ->getNode() | 53 ->getNode() |
52 ; | 54 ; |
53 | 55 |
54 $this->assertEquals( | 56 $this->assertEquals( |
55 new Stmt\ClassMethod('test', array( | 57 new Stmt\ClassMethod('test', [ |
56 'type' => Stmt\Class_::MODIFIER_PRIVATE | 58 'type' => Stmt\Class_::MODIFIER_PRIVATE |
57 )), | 59 ]), |
58 $node | 60 $node |
59 ); | 61 ); |
60 } | 62 } |
61 | 63 |
62 public function testReturnByRef() { | 64 public function testReturnByRef() { |
64 ->makeReturnByRef() | 66 ->makeReturnByRef() |
65 ->getNode() | 67 ->getNode() |
66 ; | 68 ; |
67 | 69 |
68 $this->assertEquals( | 70 $this->assertEquals( |
69 new Stmt\ClassMethod('test', array( | 71 new Stmt\ClassMethod('test', [ |
70 'byRef' => true | 72 'byRef' => true |
71 )), | 73 ]), |
72 $node | 74 $node |
73 ); | 75 ); |
74 } | 76 } |
75 | 77 |
76 public function testParams() { | 78 public function testParams() { |
77 $param1 = new Node\Param('test1'); | 79 $param1 = new Node\Param(new Variable('test1')); |
78 $param2 = new Node\Param('test2'); | 80 $param2 = new Node\Param(new Variable('test2')); |
79 $param3 = new Node\Param('test3'); | 81 $param3 = new Node\Param(new Variable('test3')); |
80 | 82 |
81 $node = $this->createMethodBuilder('test') | 83 $node = $this->createMethodBuilder('test') |
82 ->addParam($param1) | 84 ->addParam($param1) |
83 ->addParams(array($param2, $param3)) | 85 ->addParams([$param2, $param3]) |
84 ->getNode() | 86 ->getNode() |
85 ; | 87 ; |
86 | 88 |
87 $this->assertEquals( | 89 $this->assertEquals( |
88 new Stmt\ClassMethod('test', array( | 90 new Stmt\ClassMethod('test', [ |
89 'params' => array($param1, $param2, $param3) | 91 'params' => [$param1, $param2, $param3] |
90 )), | 92 ]), |
91 $node | 93 $node |
92 ); | 94 ); |
93 } | 95 } |
94 | 96 |
95 public function testStmts() { | 97 public function testStmts() { |
97 $stmt2 = new Print_(new String_('test2')); | 99 $stmt2 = new Print_(new String_('test2')); |
98 $stmt3 = new Print_(new String_('test3')); | 100 $stmt3 = new Print_(new String_('test3')); |
99 | 101 |
100 $node = $this->createMethodBuilder('test') | 102 $node = $this->createMethodBuilder('test') |
101 ->addStmt($stmt1) | 103 ->addStmt($stmt1) |
102 ->addStmts(array($stmt2, $stmt3)) | 104 ->addStmts([$stmt2, $stmt3]) |
103 ->getNode() | 105 ->getNode() |
104 ; | 106 ; |
105 | 107 |
106 $this->assertEquals( | 108 $this->assertEquals( |
107 new Stmt\ClassMethod('test', array( | 109 new Stmt\ClassMethod('test', [ |
108 'stmts' => array($stmt1, $stmt2, $stmt3) | 110 'stmts' => [ |
109 )), | 111 new Stmt\Expression($stmt1), |
112 new Stmt\Expression($stmt2), | |
113 new Stmt\Expression($stmt3), | |
114 ] | |
115 ]), | |
110 $node | 116 $node |
111 ); | 117 ); |
112 } | 118 } |
113 public function testDocComment() { | 119 public function testDocComment() { |
114 $node = $this->createMethodBuilder('test') | 120 $node = $this->createMethodBuilder('test') |
115 ->setDocComment('/** Test */') | 121 ->setDocComment('/** Test */') |
116 ->getNode(); | 122 ->getNode(); |
117 | 123 |
118 $this->assertEquals(new Stmt\ClassMethod('test', array(), array( | 124 $this->assertEquals(new Stmt\ClassMethod('test', [], [ |
119 'comments' => array(new Comment\Doc('/** Test */')) | 125 'comments' => [new Comment\Doc('/** Test */')] |
120 )), $node); | 126 ]), $node); |
121 } | 127 } |
122 | 128 |
123 public function testReturnType() { | 129 public function testReturnType() { |
124 $node = $this->createMethodBuilder('test') | 130 $node = $this->createMethodBuilder('test') |
125 ->setReturnType('bool') | 131 ->setReturnType('bool') |
126 ->getNode(); | 132 ->getNode(); |
127 $this->assertEquals(new Stmt\ClassMethod('test', array( | 133 $this->assertEquals(new Stmt\ClassMethod('test', [ |
128 'returnType' => 'bool' | 134 'returnType' => 'bool' |
129 ), array()), $node); | 135 ], []), $node); |
130 } | 136 } |
131 | 137 |
132 /** | 138 /** |
133 * @expectedException \LogicException | 139 * @expectedException \LogicException |
134 * @expectedExceptionMessage Cannot add statements to an abstract method | 140 * @expectedExceptionMessage Cannot add statements to an abstract method |