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

StaticReferenceResolverTest::resolvableExamples()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
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\Required;
8
use Doctrine\Annotations\Annotation\Target;
9
use Doctrine\Annotations\Parser\Ast\Reference;
10
use Doctrine\Annotations\Parser\Reference\Exception\ReferenceNotResolvable;
11
use Doctrine\Annotations\Parser\Reference\StaticReferenceResolver;
12
use Doctrine\Annotations\Parser\Scope;
13
use Doctrine\Tests\Annotations\Parser\ScopeMother;
14
use PHPUnit\Framework\TestCase;
15
16
class StaticReferenceResolverTest extends TestCase
17
{
18
    /** @var StaticReferenceResolver */
19
    private $resolver;
20
21
    public function setUp() : void
22
    {
23
        $this->resolver = new StaticReferenceResolver();
24
    }
25
26
    /**
27
     * @dataProvider resolvableExamples
28
     */
29
    public function testResolvesResolvableExamples(Reference $reference, Scope $scope, string $expected) : void
30
    {
31
        $result = $this->resolver->resolve($reference, $scope);
32
33
        $this->assertSame($expected, $result);
34
    }
35
36
    /**
37
     * @return mixed[]
38
     */
39
    public function resolvableExamples() : iterable
40
    {
41
        yield 'FCQN' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'FCQN' => array(ne...::class)), self::class) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
42
            new Reference(self::class, true),
43
            ScopeMother::withImports([
44
                'this' => self::class,
45
            ]),
46
            self::class,
47
        ];
48
49
        yield 'aliased' => [
50
            new Reference('foo', false),
51
            ScopeMother::withImports([
52
                'foo' => Target::class,
53
            ]),
54
            Target::class,
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider notResolvableExamples
60
     */
61
    public function testResolvesNotResolvableExamplesAndThrows(Reference $reference, Scope $scope) : void
62
    {
63
        $this->expectException(ReferenceNotResolvable::class);
64
65
        $this->resolver->resolve($reference, $scope);
66
    }
67
68
    /**
69
     * @return mixed[]
70
     */
71
    public function notResolvableExamples() : iterable
72
    {
73
        yield 'unknown FQCN' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'unknown FQCN' => ...tion\Required::class))) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
74
            new Reference(Target::class, true),
75
            ScopeMother::withImports([
76
                'that' => Required::class,
77
            ]),
78
        ];
79
80
        yield 'without alias' => [
81
            new Reference('foo', false),
82
            ScopeMother::withImports([
83
                'bar' => Target::class,
84
            ]),
85
        ];
86
    }
87
}
88