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\ReflectionFunctionAbstractName; |
9
|
|
|
use Roave\BetterReflection\BetterReflection; |
10
|
|
|
use Roave\BetterReflection\Reflection\ReflectionFunctionAbstract; |
11
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
12
|
|
|
use Roave\BetterReflection\Reflector\FunctionReflector; |
13
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \Roave\ApiCompare\Formatter\ReflectionFunctionAbstractName |
17
|
|
|
*/ |
18
|
|
|
final class ReflectionFunctionAbstractNameTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @dataProvider functionsToBeTested |
22
|
|
|
*/ |
23
|
|
|
public function testName(ReflectionFunctionAbstract $function, string $expectedName) : void |
24
|
|
|
{ |
25
|
|
|
self::assertSame($expectedName, (new ReflectionFunctionAbstractName())->__invoke($function)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** @return (string|ReflectionFunctionAbstract)[][] */ |
29
|
|
|
public function functionsToBeTested() : array |
30
|
|
|
{ |
31
|
|
|
$locator = new StringSourceLocator( |
32
|
|
|
<<<'PHP' |
33
|
|
|
<?php |
34
|
|
|
|
35
|
|
|
namespace { |
36
|
|
|
function a() {} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
namespace N1 { |
40
|
|
|
function b() {} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
namespace N2 { |
44
|
|
|
class C { |
45
|
|
|
static function d() {} |
46
|
|
|
function e() {} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
PHP |
50
|
|
|
, |
51
|
|
|
(new BetterReflection())->astLocator() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$classReflector = new ClassReflector($locator); |
55
|
|
|
$functionReflector = new FunctionReflector($locator, $classReflector); |
56
|
|
|
|
57
|
|
|
return [ |
58
|
|
|
'a' => [ |
59
|
|
|
$functionReflector->reflect('a'), |
60
|
|
|
'a()', |
61
|
|
|
], |
62
|
|
|
'N1\b' => [ |
63
|
|
|
$functionReflector->reflect('N1\b'), |
64
|
|
|
'N1\b()', |
65
|
|
|
], |
66
|
|
|
'N2\C::d' => [ |
67
|
|
|
$classReflector->reflect('N2\C')->getMethod('d'), |
68
|
|
|
'N2\C::d()', |
69
|
|
|
], |
70
|
|
|
'N2\C#e' => [ |
71
|
|
|
$classReflector->reflect('N2\C')->getMethod('e'), |
72
|
|
|
'N2\C#e()', |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|