Failed Conditions
Pull Request — new-parser-ast-metadata (#2)
by
unknown
02:41
created

FallbackReferenceResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 31
dl 0
loc 60
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\Annotation\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
    public function examples() : iterable
38
    {
39
        yield 'true FCQN' => [
40
            new Reference(self::class, true),
41
            ScopeMother::example(),
42
            self::class,
43
        ];
44
45
        yield 'random string marked as FCQN' => [
46
            new Reference('foo', true),
47
            ScopeMother::example(),
48
            'foo',
49
        ];
50
51
        yield 'fetched from imports' => [
52
            new Reference('foo', false),
53
            ScopeMother::withImports([
54
                'foo' => Target::class,
55
            ]),
56
            Target::class,
57
        ];
58
59
        yield 'of subject that cannot be referenced with namespace' => [
60
            new Reference('foo', false),
61
            ScopeMother::withSubject(new ReflectionProperty(Target::class, 'value')),
62
            'foo',
63
        ];
64
65
        yield 'global class' => [
66
            new Reference('foo', false),
67
            ScopeMother::withSubject(new ReflectionClass(stdClass::class)),
68
            'foo',
69
        ];
70
71
        $targetReflection = new ReflectionClass(Target::class);
72
73
        yield 'fallback' => [
74
            new Reference('foo', false),
75
            ScopeMother::withSubject($targetReflection),
76
            $targetReflection->getNamespaceName() . '\\' . 'foo',
77
        ];
78
    }
79
}
80