comparison vendor/nikic/php-parser/test/PhpParser/Node/NameTest.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; 3 namespace PhpParser\Node;
4 4
5 class NameTest extends \PHPUnit_Framework_TestCase 5 use PHPUnit\Framework\TestCase;
6
7 class NameTest extends TestCase
6 { 8 {
7 public function testConstruct() { 9 public function testConstruct() {
8 $name = new Name(array('foo', 'bar')); 10 $name = new Name(['foo', 'bar']);
9 $this->assertSame(array('foo', 'bar'), $name->parts); 11 $this->assertSame(['foo', 'bar'], $name->parts);
10 12
11 $name = new Name('foo\bar'); 13 $name = new Name('foo\bar');
12 $this->assertSame(array('foo', 'bar'), $name->parts); 14 $this->assertSame(['foo', 'bar'], $name->parts);
13 15
14 $name = new Name($name); 16 $name = new Name($name);
15 $this->assertSame(array('foo', 'bar'), $name->parts); 17 $this->assertSame(['foo', 'bar'], $name->parts);
16 } 18 }
17 19
18 public function testGet() { 20 public function testGet() {
19 $name = new Name('foo'); 21 $name = new Name('foo');
20 $this->assertSame('foo', $name->getFirst()); 22 $this->assertSame('foo', $name->getFirst());
24 $this->assertSame('foo', $name->getFirst()); 26 $this->assertSame('foo', $name->getFirst());
25 $this->assertSame('bar', $name->getLast()); 27 $this->assertSame('bar', $name->getLast());
26 } 28 }
27 29
28 public function testToString() { 30 public function testToString() {
29 $name = new Name('foo\bar'); 31 $name = new Name('Foo\Bar');
30 32
31 $this->assertSame('foo\bar', (string) $name); 33 $this->assertSame('Foo\Bar', (string) $name);
32 $this->assertSame('foo\bar', $name->toString()); 34 $this->assertSame('Foo\Bar', $name->toString());
35 $this->assertSame('foo\bar', $name->toLowerString());
33 } 36 }
34 37
35 public function testSlice() { 38 public function testSlice() {
36 $name = new Name('foo\bar\baz'); 39 $name = new Name('foo\bar\baz');
37 $this->assertEquals(new Name('foo\bar\baz'), $name->slice(0)); 40 $this->assertEquals(new Name('foo\bar\baz'), $name->slice(0));
96 $this->assertEquals(new Name('foo'), Name::concat(null, 'foo')); 99 $this->assertEquals(new Name('foo'), Name::concat(null, 'foo'));
97 $this->assertEquals(new Name('foo'), Name::concat('foo', null)); 100 $this->assertEquals(new Name('foo'), Name::concat('foo', null));
98 $this->assertNull(Name::concat(null, null)); 101 $this->assertNull(Name::concat(null, null));
99 } 102 }
100 103
101 public function testIs() { 104 public function testNameTypes() {
102 $name = new Name('foo'); 105 $name = new Name('foo');
103 $this->assertTrue ($name->isUnqualified()); 106 $this->assertTrue($name->isUnqualified());
104 $this->assertFalse($name->isQualified()); 107 $this->assertFalse($name->isQualified());
105 $this->assertFalse($name->isFullyQualified()); 108 $this->assertFalse($name->isFullyQualified());
106 $this->assertFalse($name->isRelative()); 109 $this->assertFalse($name->isRelative());
110 $this->assertSame('foo', $name->toCodeString());
107 111
108 $name = new Name('foo\bar'); 112 $name = new Name('foo\bar');
109 $this->assertFalse($name->isUnqualified()); 113 $this->assertFalse($name->isUnqualified());
110 $this->assertTrue ($name->isQualified()); 114 $this->assertTrue($name->isQualified());
111 $this->assertFalse($name->isFullyQualified()); 115 $this->assertFalse($name->isFullyQualified());
112 $this->assertFalse($name->isRelative()); 116 $this->assertFalse($name->isRelative());
117 $this->assertSame('foo\bar', $name->toCodeString());
113 118
114 $name = new Name\FullyQualified('foo'); 119 $name = new Name\FullyQualified('foo');
115 $this->assertFalse($name->isUnqualified()); 120 $this->assertFalse($name->isUnqualified());
116 $this->assertFalse($name->isQualified()); 121 $this->assertFalse($name->isQualified());
117 $this->assertTrue ($name->isFullyQualified()); 122 $this->assertTrue($name->isFullyQualified());
118 $this->assertFalse($name->isRelative()); 123 $this->assertFalse($name->isRelative());
124 $this->assertSame('\foo', $name->toCodeString());
119 125
120 $name = new Name\Relative('foo'); 126 $name = new Name\Relative('foo');
121 $this->assertFalse($name->isUnqualified()); 127 $this->assertFalse($name->isUnqualified());
122 $this->assertFalse($name->isQualified()); 128 $this->assertFalse($name->isQualified());
123 $this->assertFalse($name->isFullyQualified()); 129 $this->assertFalse($name->isFullyQualified());
124 $this->assertTrue ($name->isRelative()); 130 $this->assertTrue($name->isRelative());
131 $this->assertSame('namespace\foo', $name->toCodeString());
125 } 132 }
126 133
127 /** 134 /**
128 * @expectedException \InvalidArgumentException 135 * @expectedException \InvalidArgumentException
129 * @expectedExceptionMessage Expected string, array of parts or Name instance 136 * @expectedExceptionMessage Expected string, array of parts or Name instance
130 */ 137 */
131 public function testInvalidArg() { 138 public function testInvalidArg() {
132 Name::concat('foo', new \stdClass); 139 Name::concat('foo', new \stdClass);
133 } 140 }
141
142 /**
143 * @expectedException \InvalidArgumentException
144 * @expectedExceptionMessage Name cannot be empty
145 */
146 public function testInvalidEmptyString() {
147 new Name('');
148 }
149
150 /**
151 * @expectedException \InvalidArgumentException
152 * @expectedExceptionMessage Name cannot be empty
153 */
154 public function testInvalidEmptyArray() {
155 new Name([]);
156 }
157
158 /** @dataProvider provideTestIsSpecialClassName */
159 public function testIsSpecialClassName($name, $expected) {
160 $name = new Name($name);
161 $this->assertSame($expected, $name->isSpecialClassName());
162 }
163
164 public function provideTestIsSpecialClassName() {
165 return [
166 ['self', true],
167 ['PARENT', true],
168 ['Static', true],
169 ['self\not', false],
170 ['not\self', false],
171 ];
172 }
134 } 173 }