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