1 | <?php |
||
10 | class DeclarationTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @dataProvider nameProvider |
||
14 | * |
||
15 | * @param \ReflectionClass $parent |
||
16 | * @param string $class |
||
17 | * @param string $expected |
||
18 | */ |
||
19 | public function testShortName(\ReflectionClass $parent, string $class, string $expected): void |
||
20 | { |
||
21 | $declaration = Declarations::createFromReflection($parent, $class); |
||
22 | $this->assertSame($expected, $declaration->class->getShortName()); |
||
23 | } |
||
24 | |||
25 | public function nameProvider(): array |
||
26 | { |
||
27 | $r = new \ReflectionClass(\Example::class); |
||
28 | |||
29 | return [ |
||
30 | [$r, 'ExampleProxy\\', 'ExampleProxy'], |
||
31 | [$r, 'ExampleProxy', 'ExampleProxy'], |
||
32 | [$r, '\ExampleProxy', 'ExampleProxy'], |
||
33 | [$r, '\Namespaced\Name\Of\ExampleProxy', 'ExampleProxy'], |
||
34 | ]; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @dataProvider namespaceProvider |
||
39 | * |
||
40 | * @param \ReflectionClass $parent |
||
41 | * @param string $class |
||
42 | * @param string|null $expected |
||
43 | */ |
||
44 | public function testNamespace(\ReflectionClass $parent, string $class, ?string $expected): void |
||
45 | { |
||
46 | $declaration = Declarations::createFromReflection($parent, $class); |
||
47 | $this->assertSame($expected, $declaration->class->getNamespaceName()); |
||
48 | } |
||
49 | |||
50 | public function namespaceProvider(): array |
||
51 | { |
||
52 | $r1 = new \ReflectionClass(\Example::class); |
||
53 | $r2 = new \ReflectionClass(HasNamespaceExample::class); |
||
54 | |||
55 | return [ |
||
56 | [$r1, 'ExampleProxy\\', null], |
||
57 | [$r1, 'ExampleProxy', null], |
||
58 | [$r1, '\ExampleProxy', null], |
||
59 | [$r2, '\ExampleProxy', null], |
||
60 | [$r2, 'ExampleProxy', $r2->getNamespaceName()], |
||
61 | [$r2, 'ExampleProxy\\', $r2->getNamespaceName()], |
||
62 | [$r2, '\Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of'], |
||
63 | [$r2, 'Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of'], |
||
64 | ]; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @dataProvider fullNameProvider |
||
69 | * |
||
70 | * @param \ReflectionClass $parent |
||
71 | * @param string $class |
||
72 | * @param string|null $expected |
||
73 | */ |
||
74 | public function testFullName(\ReflectionClass $parent, string $class, ?string $expected): void |
||
75 | { |
||
76 | $declaration = Declarations::createFromReflection($parent, $class); |
||
77 | $this->assertSame($expected, $declaration->class->getFullName()); |
||
78 | } |
||
79 | |||
80 | public function fullNameProvider(): array |
||
81 | { |
||
82 | $r1 = new \ReflectionClass(\Example::class); |
||
83 | $r2 = new \ReflectionClass(HasNamespaceExample::class); |
||
84 | |||
85 | return [ |
||
86 | [$r1, 'ExampleProxy', '\ExampleProxy'], |
||
87 | [$r1, '\ExampleProxy', '\ExampleProxy'], |
||
88 | [$r2, '\ExampleProxy', '\ExampleProxy'], |
||
89 | [$r2, 'ExampleProxy', $r2->getNamespaceName() . '\\' . 'ExampleProxy'], |
||
90 | [$r2, 'ExampleProxy\\', $r2->getNamespaceName() . '\\' . 'ExampleProxy'], |
||
91 | [$r2, '\Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of\ExampleProxy'], |
||
92 | [$r2, 'Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of\ExampleProxy'], |
||
93 | ]; |
||
94 | } |
||
95 | } |