|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* phpDocumentor |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @link http://phpdoc.org |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection; |
|
15
|
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\Fqsen |
|
21
|
|
|
*/ |
|
22
|
|
|
class FqsenTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @covers ::__construct |
|
26
|
|
|
* @dataProvider validFqsenProvider |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testValidFormats(string $fqsen, string $name) : void |
|
29
|
|
|
{ |
|
30
|
|
|
$instance = new Fqsen($fqsen); |
|
31
|
|
|
$this->assertEquals($name, $instance->getName()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Data provider for ValidFormats tests. Contains a complete list from psr-5 draft. |
|
36
|
|
|
* |
|
37
|
|
|
* @return array<array<string>> |
|
38
|
|
|
*/ |
|
39
|
|
|
public function validFqsenProvider() : array |
|
40
|
|
|
{ |
|
41
|
|
|
return [ |
|
42
|
|
|
['\\', ''], |
|
43
|
|
|
['\My\Space', 'Space'], |
|
44
|
|
|
['\My\Space\myFunction()', 'myFunction'], |
|
45
|
|
|
['\My\Space\MY_CONSTANT', 'MY_CONSTANT'], |
|
46
|
|
|
['\My\Space\MY_CONSTANT2', 'MY_CONSTANT2'], |
|
47
|
|
|
['\My\Space\MyClass', 'MyClass'], |
|
48
|
|
|
['\My\Space\MyInterface', 'MyInterface'], |
|
49
|
|
|
['\My\Space\Option«T»', 'Option«T»'], |
|
50
|
|
|
['\My\Space\MyTrait', 'MyTrait'], |
|
51
|
|
|
['\My\Space\MyClass::myMethod()', 'myMethod'], |
|
52
|
|
|
['\My\Space\MyClass::$my_property', 'my_property'], |
|
53
|
|
|
['\My\Space\MyClass::MY_CONSTANT', 'MY_CONSTANT'], |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @covers ::__construct |
|
59
|
|
|
* @dataProvider invalidFqsenProvider |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testInValidFormats(string $fqsen) : void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
64
|
|
|
new Fqsen($fqsen); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Data provider for invalidFormats tests. Contains a complete list from psr-5 draft. |
|
69
|
|
|
* |
|
70
|
|
|
* @return array<array<string>> |
|
71
|
|
|
*/ |
|
72
|
|
|
public function invalidFqsenProvider() : array |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
|
|
['\My\*'], |
|
76
|
|
|
['\My\Space\.()'], |
|
77
|
|
|
['My\Space'], |
|
78
|
|
|
['1_function()'], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @covers ::__construct |
|
84
|
|
|
* @covers ::__toString |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testToString() : void |
|
87
|
|
|
{ |
|
88
|
|
|
$className = new Fqsen('\\phpDocumentor\\Application'); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertEquals('\\phpDocumentor\\Application', (string) $className); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|