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

StaticReferenceResolverTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 25
dl 0
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A notResolvableExamples() 0 13 1
A testResolvesNotResolvableExamplesAndThrows() 0 5 1
A resolvableExamples() 0 16 1
A testResolvesResolvableExamples() 0 5 1
A setUp() 0 3 1
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\Annotation\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
    public function resolvableExamples() : iterable
38
    {
39
        yield 'FCQN' => [
40
            new Reference(self::class, true),
41
            ScopeMother::withImports([
42
                'this' => self::class,
43
            ]),
44
            self::class,
45
        ];
46
47
        yield 'aliased' => [
48
            new Reference('foo', false),
49
            ScopeMother::withImports([
50
                'foo' => Target::class,
51
            ]),
52
            Target::class,
53
        ];
54
    }
55
56
    /**
57
     * @dataProvider notResolvableExamples
58
     */
59
    public function testResolvesNotResolvableExamplesAndThrows(Reference $reference, Scope $scope) : void
60
    {
61
        $this->expectException(ReferenceNotResolvable::class);
62
63
        $this->resolver->resolve($reference, $scope);
64
    }
65
66
    public function notResolvableExamples() : iterable
67
    {
68
        yield 'unknown FQCN' => [
69
            new Reference(Target::class, true),
70
            ScopeMother::withImports([
71
                'that' => Required::class,
72
            ]),
73
        ];
74
75
        yield 'without alias' => [
76
            new Reference('foo', false),
77
            ScopeMother::withImports([
78
                'bar' => Target::class,
79
            ]),
80
        ];
81
    }
82
}
83