Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/NameContextTest.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 | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php declare(strict_types=1); | |
2 | |
3 namespace PhpParser; | |
4 | |
5 use PhpParser\Node\Name; | |
6 use PhpParser\Node\Stmt\Use_; | |
7 use PHPUnit\Framework\TestCase; | |
8 | |
9 class NameContextTest extends TestCase | |
10 { | |
11 /** | |
12 * @dataProvider provideTestGetPossibleNames | |
13 */ | |
14 public function testGetPossibleNames($type, $name, $expectedPossibleNames) { | |
15 $nameContext = new NameContext(new ErrorHandler\Throwing()); | |
16 $nameContext->startNamespace(new Name('NS')); | |
17 $nameContext->addAlias(new Name('Foo'), 'Foo', Use_::TYPE_NORMAL); | |
18 $nameContext->addAlias(new Name('Foo\Bar'), 'Alias', Use_::TYPE_NORMAL); | |
19 $nameContext->addAlias(new Name('Foo\fn'), 'fn', Use_::TYPE_FUNCTION); | |
20 $nameContext->addAlias(new Name('Foo\CN'), 'CN', Use_::TYPE_CONSTANT); | |
21 | |
22 $possibleNames = $nameContext->getPossibleNames($name, $type); | |
23 $possibleNames = array_map(function (Name $name) { | |
24 return $name->toCodeString(); | |
25 }, $possibleNames); | |
26 | |
27 $this->assertSame($expectedPossibleNames, $possibleNames); | |
28 | |
29 // Here the last name is always the shortest one | |
30 $expectedShortName = $expectedPossibleNames[count($expectedPossibleNames) - 1]; | |
31 $this->assertSame( | |
32 $expectedShortName, | |
33 $nameContext->getShortName($name, $type)->toCodeString() | |
34 ); | |
35 } | |
36 | |
37 public function provideTestGetPossibleNames() { | |
38 return [ | |
39 [Use_::TYPE_NORMAL, 'Test', ['\Test']], | |
40 [Use_::TYPE_NORMAL, 'Test\Namespaced', ['\Test\Namespaced']], | |
41 [Use_::TYPE_NORMAL, 'NS\Test', ['\NS\Test', 'Test']], | |
42 [Use_::TYPE_NORMAL, 'ns\Test', ['\ns\Test', 'Test']], | |
43 [Use_::TYPE_NORMAL, 'NS\Foo\Bar', ['\NS\Foo\Bar']], | |
44 [Use_::TYPE_NORMAL, 'ns\foo\Bar', ['\ns\foo\Bar']], | |
45 [Use_::TYPE_NORMAL, 'Foo', ['\Foo', 'Foo']], | |
46 [Use_::TYPE_NORMAL, 'Foo\Bar', ['\Foo\Bar', 'Foo\Bar', 'Alias']], | |
47 [Use_::TYPE_NORMAL, 'Foo\Bar\Baz', ['\Foo\Bar\Baz', 'Foo\Bar\Baz', 'Alias\Baz']], | |
48 [Use_::TYPE_NORMAL, 'Foo\fn\Bar', ['\Foo\fn\Bar', 'Foo\fn\Bar']], | |
49 [Use_::TYPE_FUNCTION, 'Foo\fn\bar', ['\Foo\fn\bar', 'Foo\fn\bar']], | |
50 [Use_::TYPE_FUNCTION, 'Foo\fn', ['\Foo\fn', 'Foo\fn', 'fn']], | |
51 [Use_::TYPE_FUNCTION, 'Foo\FN', ['\Foo\FN', 'Foo\FN', 'fn']], | |
52 [Use_::TYPE_CONSTANT, 'Foo\CN\BAR', ['\Foo\CN\BAR', 'Foo\CN\BAR']], | |
53 [Use_::TYPE_CONSTANT, 'Foo\CN', ['\Foo\CN', 'Foo\CN', 'CN']], | |
54 [Use_::TYPE_CONSTANT, 'foo\CN', ['\foo\CN', 'Foo\CN', 'CN']], | |
55 [Use_::TYPE_CONSTANT, 'foo\cn', ['\foo\cn', 'Foo\cn']], | |
56 // self/parent/static must not be fully qualified | |
57 [Use_::TYPE_NORMAL, 'self', ['self']], | |
58 [Use_::TYPE_NORMAL, 'parent', ['parent']], | |
59 [Use_::TYPE_NORMAL, 'static', ['static']], | |
60 // true/false/null do not need to be fully qualified, even in namespaces | |
61 [Use_::TYPE_CONSTANT, 'true', ['\true', 'true']], | |
62 [Use_::TYPE_CONSTANT, 'false', ['\false', 'false']], | |
63 [Use_::TYPE_CONSTANT, 'null', ['\null', 'null']], | |
64 ]; | |
65 } | |
66 } |