comparison vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.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\Node\Stmt; 3 namespace PhpParser\Node\Stmt;
4 4
5 class ClassMethodTest extends \PHPUnit_Framework_TestCase 5 use PhpParser\Node\Expr\Variable;
6 use PhpParser\Node\Name;
7 use PhpParser\Node\Param;
8 use PHPUnit\Framework\TestCase;
9
10 class ClassMethodTest extends TestCase
6 { 11 {
7 /** 12 /**
8 * @dataProvider provideModifiers 13 * @dataProvider provideModifiers
9 */ 14 */
10 public function testModifiers($modifier) { 15 public function testModifiers($modifier) {
11 $node = new ClassMethod('foo', array( 16 $node = new ClassMethod('foo', [
12 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) 17 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
13 )); 18 ]);
14 19
15 $this->assertTrue($node->{'is' . $modifier}()); 20 $this->assertTrue($node->{'is' . $modifier}());
16 } 21 }
17 22
18 public function testNoModifiers() { 23 public function testNoModifiers() {
19 $node = new ClassMethod('foo', array('type' => 0)); 24 $node = new ClassMethod('foo', ['type' => 0]);
20 25
21 $this->assertTrue($node->isPublic()); 26 $this->assertTrue($node->isPublic());
22 $this->assertFalse($node->isProtected()); 27 $this->assertFalse($node->isProtected());
23 $this->assertFalse($node->isPrivate()); 28 $this->assertFalse($node->isPrivate());
24 $this->assertFalse($node->isAbstract()); 29 $this->assertFalse($node->isAbstract());
25 $this->assertFalse($node->isFinal()); 30 $this->assertFalse($node->isFinal());
26 $this->assertFalse($node->isStatic()); 31 $this->assertFalse($node->isStatic());
32 $this->assertFalse($node->isMagic());
27 } 33 }
28 34
29 public function provideModifiers() { 35 public function provideModifiers() {
30 return array( 36 return [
31 array('public'), 37 ['public'],
32 array('protected'), 38 ['protected'],
33 array('private'), 39 ['private'],
34 array('abstract'), 40 ['abstract'],
35 array('final'), 41 ['final'],
36 array('static'), 42 ['static'],
37 ); 43 ];
38 } 44 }
39 45
40 /** 46 /**
41 * Checks that implicit public modifier detection for method is working 47 * Checks that implicit public modifier detection for method is working
42 * 48 *
43 * @dataProvider implicitPublicModifiers 49 * @dataProvider implicitPublicModifiers
44 * 50 *
45 * @param integer $modifier Node type modifier 51 * @param string $modifier Node type modifier
46 */ 52 */
47 public function testImplicitPublic($modifier) 53 public function testImplicitPublic(string $modifier)
48 { 54 {
49 $node = new ClassMethod('foo', array( 55 $node = new ClassMethod('foo', [
50 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) 56 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
51 )); 57 ]);
52 58
53 $this->assertTrue($node->isPublic(), 'Node should be implicitly public'); 59 $this->assertTrue($node->isPublic(), 'Node should be implicitly public');
54 } 60 }
55 61
56 public function implicitPublicModifiers() { 62 public function implicitPublicModifiers() {
57 return array( 63 return [
58 array('abstract'), 64 ['abstract'],
59 array('final'), 65 ['final'],
60 array('static'), 66 ['static'],
61 ); 67 ];
68 }
69
70 /**
71 * @dataProvider provideMagics
72 *
73 * @param string $name Node name
74 */
75 public function testMagic(string $name) {
76 $node = new ClassMethod($name);
77 $this->assertTrue($node->isMagic(), 'Method should be magic');
78 }
79
80 public function provideMagics() {
81 return [
82 ['__construct'],
83 ['__DESTRUCT'],
84 ['__caLL'],
85 ['__callstatic'],
86 ['__get'],
87 ['__set'],
88 ['__isset'],
89 ['__unset'],
90 ['__sleep'],
91 ['__wakeup'],
92 ['__tostring'],
93 ['__set_state'],
94 ['__clone'],
95 ['__invoke'],
96 ['__debuginfo'],
97 ];
98 }
99
100 public function testFunctionLike() {
101 $param = new Param(new Variable('a'));
102 $type = new Name('Foo');
103 $return = new Return_(new Variable('a'));
104 $method = new ClassMethod('test', [
105 'byRef' => false,
106 'params' => [$param],
107 'returnType' => $type,
108 'stmts' => [$return],
109 ]);
110
111 $this->assertFalse($method->returnsByRef());
112 $this->assertSame([$param], $method->getParams());
113 $this->assertSame($type, $method->getReturnType());
114 $this->assertSame([$return], $method->getStmts());
115
116 $method = new ClassMethod('test', [
117 'byRef' => true,
118 'stmts' => null,
119 ]);
120
121 $this->assertTrue($method->returnsByRef());
122 $this->assertNull($method->getStmts());
62 } 123 }
63 } 124 }