Failed Conditions
Push — new-parser-ast-metadata ( 6127e0...5a4a16 )
by Michael
12s
created

FallbackReferenceResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 31
dl 0
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testResolvesExamples() 0 5 1
A examples() 0 40 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations\Parser\Reference;
6
7
use Doctrine\Annotations\Annotation\Target;
8
use Doctrine\Annotations\Parser\Ast\Reference;
9
use Doctrine\Annotations\Parser\Reference\FallbackReferenceResolver;
10
use Doctrine\Annotations\Parser\Scope;
11
use Doctrine\Tests\Annotations\Parser\ScopeMother;
12
use PHPUnit\Framework\TestCase;
13
use ReflectionClass;
14
use ReflectionProperty;
15
use stdClass;
16
17
class FallbackReferenceResolverTest extends TestCase
18
{
19
    /** @var FallbackReferenceResolver */
20
    private $resolver;
21
22
    public function setUp() : void
23
    {
24
        $this->resolver = new FallbackReferenceResolver();
25
    }
26
27
    /**
28
     * @dataProvider examples
29
     */
30
    public function testResolvesExamples(Reference $reference, Scope $scope, string $expected) : void
31
    {
32
        $result = $this->resolver->resolve($reference, $scope);
33
34
        $this->assertSame($expected, $result);
35
    }
36
37
    /**
38
     * @return mixed[]
39
     */
40
    public function examples() : iterable
41
    {
42
        yield 'true FCQN' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'true FCQN' => arr...example(), self::class) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
43
            new Reference(self::class, true),
44
            ScopeMother::example(),
45
            self::class,
46
        ];
47
48
        yield 'random string marked as FCQN' => [
49
            new Reference('foo', true),
50
            ScopeMother::example(),
51
            'foo',
52
        ];
53
54
        yield 'fetched from imports' => [
55
            new Reference('foo', false),
56
            ScopeMother::withImports([
57
                'foo' => Target::class,
58
            ]),
59
            Target::class,
60
        ];
61
62
        yield 'of subject that cannot be referenced with namespace' => [
63
            new Reference('foo', false),
64
            ScopeMother::withSubject(new ReflectionProperty(Target::class, 'value')),
65
            'foo',
66
        ];
67
68
        yield 'global class' => [
69
            new Reference('foo', false),
70
            ScopeMother::withSubject(new ReflectionClass(stdClass::class)),
71
            'foo',
72
        ];
73
74
        $targetReflection = new ReflectionClass(Target::class);
75
76
        yield 'fallback' => [
77
            new Reference('foo', false),
78
            ScopeMother::withSubject($targetReflection),
79
            $targetReflection->getNamespaceName() . '\\foo',
80
        ];
81
    }
82
}
83