|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\Formatter; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Roave\BackwardCompatibility\Formatter\ReflectionPropertyName; |
|
9
|
|
|
use Roave\BetterReflection\BetterReflection; |
|
10
|
|
|
use Roave\BetterReflection\Reflection\ReflectionProperty; |
|
11
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
|
12
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
|
13
|
|
|
use function array_combine; |
|
14
|
|
|
use function array_keys; |
|
15
|
|
|
use function array_map; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @covers \Roave\BackwardCompatibility\Formatter\ReflectionPropertyName |
|
19
|
|
|
*/ |
|
20
|
|
|
final class ReflectionPropertyNameTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider propertiesToBeTested |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testName(ReflectionProperty $property, string $expectedName) : void |
|
26
|
|
|
{ |
|
27
|
|
|
self::assertSame($expectedName, (new ReflectionPropertyName())->__invoke($property)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** @return (string|ReflectionProperty)[][] */ |
|
31
|
|
|
public function propertiesToBeTested() : array |
|
32
|
|
|
{ |
|
33
|
|
|
$locator = new StringSourceLocator( |
|
34
|
|
|
<<<'PHP' |
|
35
|
|
|
<?php |
|
36
|
|
|
|
|
37
|
|
|
namespace { |
|
38
|
|
|
class A { |
|
39
|
|
|
public static $b; |
|
40
|
|
|
public $c; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
namespace N1 { |
|
44
|
|
|
class D { |
|
45
|
|
|
public static $e; |
|
46
|
|
|
public $f; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
PHP |
|
50
|
|
|
, |
|
51
|
|
|
(new BetterReflection())->astLocator() |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$classReflector = new ClassReflector($locator); |
|
55
|
|
|
|
|
56
|
|
|
$properties = [ |
|
57
|
|
|
'A::$b' => $classReflector->reflect('A')->getProperty('b'), |
|
58
|
|
|
'A#$c' => $classReflector->reflect('A')->getProperty('c'), |
|
59
|
|
|
'N1\D::$e' => $classReflector->reflect('N1\D')->getProperty('e'), |
|
60
|
|
|
'N1\D#$f' => $classReflector->reflect('N1\D')->getProperty('f'), |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
return array_combine( |
|
64
|
|
|
array_keys($properties), |
|
65
|
|
|
array_map( |
|
66
|
|
|
function (string $expectedMessage, ReflectionProperty $property) : array { |
|
67
|
|
|
return [$property, $expectedMessage]; |
|
68
|
|
|
}, |
|
69
|
|
|
array_keys($properties), |
|
70
|
|
|
$properties |
|
71
|
|
|
) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|