comparison vendor/nikic/php-parser/test/PhpParser/Builder/PropertyTest.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\Expr; 6 use PhpParser\Node\Expr;
7 use PhpParser\Node\Name; 7 use PhpParser\Node\Name;
8 use PhpParser\Node\Scalar; 8 use PhpParser\Node\Scalar;
9 use PhpParser\Node\Stmt; 9 use PhpParser\Node\Stmt;
10 use PHPUnit\Framework\TestCase;
10 11
11 class PropertyTest extends \PHPUnit_Framework_TestCase 12 class PropertyTest extends TestCase
12 { 13 {
13 public function createPropertyBuilder($name) { 14 public function createPropertyBuilder($name) {
14 return new Property($name); 15 return new Property($name);
15 } 16 }
16 17
23 24
24 $this->assertEquals( 25 $this->assertEquals(
25 new Stmt\Property( 26 new Stmt\Property(
26 Stmt\Class_::MODIFIER_PRIVATE 27 Stmt\Class_::MODIFIER_PRIVATE
27 | Stmt\Class_::MODIFIER_STATIC, 28 | Stmt\Class_::MODIFIER_STATIC,
28 array( 29 [
29 new Stmt\PropertyProperty('test') 30 new Stmt\PropertyProperty('test')
30 ) 31 ]
31 ), 32 ),
32 $node 33 $node
33 ); 34 );
34 35
35 $node = $this->createPropertyBuilder('test') 36 $node = $this->createPropertyBuilder('test')
38 ; 39 ;
39 40
40 $this->assertEquals( 41 $this->assertEquals(
41 new Stmt\Property( 42 new Stmt\Property(
42 Stmt\Class_::MODIFIER_PROTECTED, 43 Stmt\Class_::MODIFIER_PROTECTED,
43 array( 44 [
44 new Stmt\PropertyProperty('test') 45 new Stmt\PropertyProperty('test')
45 ) 46 ]
46 ), 47 ),
47 $node 48 $node
48 ); 49 );
49 50
50 $node = $this->createPropertyBuilder('test') 51 $node = $this->createPropertyBuilder('test')
53 ; 54 ;
54 55
55 $this->assertEquals( 56 $this->assertEquals(
56 new Stmt\Property( 57 new Stmt\Property(
57 Stmt\Class_::MODIFIER_PUBLIC, 58 Stmt\Class_::MODIFIER_PUBLIC,
58 array( 59 [
59 new Stmt\PropertyProperty('test') 60 new Stmt\PropertyProperty('test')
60 ) 61 ]
61 ), 62 ),
62 $node 63 $node
63 ); 64 );
64 } 65 }
65 66
68 ->setDocComment('/** Test */') 69 ->setDocComment('/** Test */')
69 ->getNode(); 70 ->getNode();
70 71
71 $this->assertEquals(new Stmt\Property( 72 $this->assertEquals(new Stmt\Property(
72 Stmt\Class_::MODIFIER_PUBLIC, 73 Stmt\Class_::MODIFIER_PUBLIC,
73 array( 74 [
74 new Stmt\PropertyProperty('test') 75 new Stmt\PropertyProperty('test')
75 ), 76 ],
76 array( 77 [
77 'comments' => array(new Comment\Doc('/** Test */')) 78 'comments' => [new Comment\Doc('/** Test */')]
78 ) 79 ]
79 ), $node); 80 ), $node);
80 } 81 }
81 82
82 /** 83 /**
83 * @dataProvider provideTestDefaultValues 84 * @dataProvider provideTestDefaultValues
90 91
91 $this->assertEquals($expectedValueNode, $node->props[0]->default); 92 $this->assertEquals($expectedValueNode, $node->props[0]->default);
92 } 93 }
93 94
94 public function provideTestDefaultValues() { 95 public function provideTestDefaultValues() {
95 return array( 96 return [
96 array( 97 [
97 null, 98 null,
98 new Expr\ConstFetch(new Name('null')) 99 new Expr\ConstFetch(new Name('null'))
99 ), 100 ],
100 array( 101 [
101 true, 102 true,
102 new Expr\ConstFetch(new Name('true')) 103 new Expr\ConstFetch(new Name('true'))
103 ), 104 ],
104 array( 105 [
105 false, 106 false,
106 new Expr\ConstFetch(new Name('false')) 107 new Expr\ConstFetch(new Name('false'))
107 ), 108 ],
108 array( 109 [
109 31415, 110 31415,
110 new Scalar\LNumber(31415) 111 new Scalar\LNumber(31415)
111 ), 112 ],
112 array( 113 [
113 3.1415, 114 3.1415,
114 new Scalar\DNumber(3.1415) 115 new Scalar\DNumber(3.1415)
115 ), 116 ],
116 array( 117 [
117 'Hallo World', 118 'Hallo World',
118 new Scalar\String_('Hallo World') 119 new Scalar\String_('Hallo World')
119 ), 120 ],
120 array( 121 [
121 array(1, 2, 3), 122 [1, 2, 3],
122 new Expr\Array_(array( 123 new Expr\Array_([
123 new Expr\ArrayItem(new Scalar\LNumber(1)), 124 new Expr\ArrayItem(new Scalar\LNumber(1)),
124 new Expr\ArrayItem(new Scalar\LNumber(2)), 125 new Expr\ArrayItem(new Scalar\LNumber(2)),
125 new Expr\ArrayItem(new Scalar\LNumber(3)), 126 new Expr\ArrayItem(new Scalar\LNumber(3)),
126 )) 127 ])
127 ), 128 ],
128 array( 129 [
129 array('foo' => 'bar', 'bar' => 'foo'), 130 ['foo' => 'bar', 'bar' => 'foo'],
130 new Expr\Array_(array( 131 new Expr\Array_([
131 new Expr\ArrayItem( 132 new Expr\ArrayItem(
132 new Scalar\String_('bar'), 133 new Scalar\String_('bar'),
133 new Scalar\String_('foo') 134 new Scalar\String_('foo')
134 ), 135 ),
135 new Expr\ArrayItem( 136 new Expr\ArrayItem(
136 new Scalar\String_('foo'), 137 new Scalar\String_('foo'),
137 new Scalar\String_('bar') 138 new Scalar\String_('bar')
138 ), 139 ),
139 )) 140 ])
140 ), 141 ],
141 array( 142 [
142 new Scalar\MagicConst\Dir, 143 new Scalar\MagicConst\Dir,
143 new Scalar\MagicConst\Dir 144 new Scalar\MagicConst\Dir
144 ) 145 ]
145 ); 146 ];
146 } 147 }
147 } 148 }