ReflectionFunctionAbstractNameTest::testName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\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\BackwardCompatibility\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
    /**
29
     * @return array<string, array<int, string|ReflectionFunctionAbstract>>
30
     *
31
     * @psalm-return array<string, array{0: ReflectionFunctionAbstract, 1: string}>
32
     */
33
    public function functionsToBeTested() : array
34
    {
35
        $locator = new StringSourceLocator(
36
            <<<'PHP'
37
<?php
38
39
namespace {
40
   function a() {}
41
}
42
43
namespace N1 {
44
    function b() {}
45
}
46
47
namespace N2 {
48
   class C {
49
       static function d() {}
50
       function e() {}
51
   }
52
}
53
PHP
54
            ,
55
            (new BetterReflection())->astLocator()
56
        );
57
58
        $classReflector    = new ClassReflector($locator);
59
        $functionReflector = new FunctionReflector($locator, $classReflector);
60
61
        return [
62
            'a'       => [
63
                $functionReflector->reflect('a'),
64
                'a()',
65
            ],
66
            'N1\b'    => [
67
                $functionReflector->reflect('N1\b'),
68
                'N1\b()',
69
            ],
70
            'N2\C::d' => [
71
                $classReflector->reflect('N2\C')->getMethod('d'),
72
                'N2\C::d()',
73
            ],
74
            'N2\C#e'  => [
75
                $classReflector->reflect('N2\C')->getMethod('e'),
76
                'N2\C#e()',
77
            ],
78
        ];
79
    }
80
}
81