comparison vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 5fb285c0d0e3
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php declare(strict_types=1); 1 <?php declare(strict_types=1);
2 2
3 namespace PhpParser\Node; 3 namespace PhpParser\Node;
4 4
5 use PHPUnit\Framework\TestCase; 5 class NameTest extends \PHPUnit\Framework\TestCase
6
7 class NameTest extends TestCase
8 { 6 {
9 public function testConstruct() { 7 public function testConstruct() {
10 $name = new Name(['foo', 'bar']); 8 $name = new Name(['foo', 'bar']);
11 $this->assertSame(['foo', 'bar'], $name->parts); 9 $this->assertSame(['foo', 'bar'], $name->parts);
12 10
49 $this->assertEquals(new Name('bar'), $name->slice(-2, 1)); 47 $this->assertEquals(new Name('bar'), $name->slice(-2, 1));
50 $this->assertEquals(new Name('bar'), $name->slice(-2, -1)); 48 $this->assertEquals(new Name('bar'), $name->slice(-2, -1));
51 $this->assertNull($name->slice(-2, -2)); 49 $this->assertNull($name->slice(-2, -2));
52 } 50 }
53 51
54 /**
55 * @expectedException \OutOfBoundsException
56 * @expectedExceptionMessage Offset 4 is out of bounds
57 */
58 public function testSliceOffsetTooLarge() { 52 public function testSliceOffsetTooLarge() {
53 $this->expectException(\OutOfBoundsException::class);
54 $this->expectExceptionMessage('Offset 4 is out of bounds');
59 (new Name('foo\bar\baz'))->slice(4); 55 (new Name('foo\bar\baz'))->slice(4);
60 } 56 }
61 57
62 /**
63 * @expectedException \OutOfBoundsException
64 * @expectedExceptionMessage Offset -4 is out of bounds
65 */
66 public function testSliceOffsetTooSmall() { 58 public function testSliceOffsetTooSmall() {
59 $this->expectException(\OutOfBoundsException::class);
60 $this->expectExceptionMessage('Offset -4 is out of bounds');
67 (new Name('foo\bar\baz'))->slice(-4); 61 (new Name('foo\bar\baz'))->slice(-4);
68 } 62 }
69 63
70 /**
71 * @expectedException \OutOfBoundsException
72 * @expectedExceptionMessage Length 4 is out of bounds
73 */
74 public function testSliceLengthTooLarge() { 64 public function testSliceLengthTooLarge() {
65 $this->expectException(\OutOfBoundsException::class);
66 $this->expectExceptionMessage('Length 4 is out of bounds');
75 (new Name('foo\bar\baz'))->slice(0, 4); 67 (new Name('foo\bar\baz'))->slice(0, 4);
76 } 68 }
77 69
78 /**
79 * @expectedException \OutOfBoundsException
80 * @expectedExceptionMessage Length -4 is out of bounds
81 */
82 public function testSliceLengthTooSmall() { 70 public function testSliceLengthTooSmall() {
71 $this->expectException(\OutOfBoundsException::class);
72 $this->expectExceptionMessage('Length -4 is out of bounds');
83 (new Name('foo\bar\baz'))->slice(0, -4); 73 (new Name('foo\bar\baz'))->slice(0, -4);
84 } 74 }
85 75
86 public function testConcat() { 76 public function testConcat() {
87 $this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz')); 77 $this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz'));
129 $this->assertFalse($name->isFullyQualified()); 119 $this->assertFalse($name->isFullyQualified());
130 $this->assertTrue($name->isRelative()); 120 $this->assertTrue($name->isRelative());
131 $this->assertSame('namespace\foo', $name->toCodeString()); 121 $this->assertSame('namespace\foo', $name->toCodeString());
132 } 122 }
133 123
134 /**
135 * @expectedException \InvalidArgumentException
136 * @expectedExceptionMessage Expected string, array of parts or Name instance
137 */
138 public function testInvalidArg() { 124 public function testInvalidArg() {
125 $this->expectException(\InvalidArgumentException::class);
126 $this->expectExceptionMessage('Expected string, array of parts or Name instance');
139 Name::concat('foo', new \stdClass); 127 Name::concat('foo', new \stdClass);
140 } 128 }
141 129
142 /**
143 * @expectedException \InvalidArgumentException
144 * @expectedExceptionMessage Name cannot be empty
145 */
146 public function testInvalidEmptyString() { 130 public function testInvalidEmptyString() {
131 $this->expectException(\InvalidArgumentException::class);
132 $this->expectExceptionMessage('Name cannot be empty');
147 new Name(''); 133 new Name('');
148 } 134 }
149 135
150 /**
151 * @expectedException \InvalidArgumentException
152 * @expectedExceptionMessage Name cannot be empty
153 */
154 public function testInvalidEmptyArray() { 136 public function testInvalidEmptyArray() {
137 $this->expectException(\InvalidArgumentException::class);
138 $this->expectExceptionMessage('Name cannot be empty');
155 new Name([]); 139 new Name([]);
156 } 140 }
157 141
158 /** @dataProvider provideTestIsSpecialClassName */ 142 /** @dataProvider provideTestIsSpecialClassName */
159 public function testIsSpecialClassName($name, $expected) { 143 public function testIsSpecialClassName($name, $expected) {