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

FallbackReferenceResolverTest::examples()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 40
rs 9.504
c 0
b 0
f 0
cc 1
nc 1
nop 0
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