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

MetadataCollectorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 61
dl 0
loc 115
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testMetadata() 0 9 1
A docBlocksProvider() 0 80 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations\Metadata;
6
7
use Doctrine\Annotations\Metadata\AnnotationMetadata;
8
use Doctrine\Annotations\Metadata\AnnotationTarget;
9
use Doctrine\Annotations\Metadata\Assembler\AnnotationMetadataAssembler;
10
use Doctrine\Annotations\Metadata\MetadataCollection;
11
use Doctrine\Annotations\Metadata\MetadataCollector;
12
use Doctrine\Annotations\Parser\Ast\Annotation;
13
use Doctrine\Annotations\Parser\Ast\Annotations;
14
use Doctrine\Annotations\Parser\Ast\Parameter\UnnamedParameter;
15
use Doctrine\Annotations\Parser\Ast\Parameters;
16
use Doctrine\Annotations\Parser\Ast\Reference;
17
use Doctrine\Annotations\Parser\Scope;
18
use Doctrine\Tests\Annotations\Annotation\Parser\Reference\IdentifierPassingReferenceResolver;
19
use Doctrine\Tests\Annotations\Annotation\Parser\ScopeMother;
20
use Doctrine\Tests\Annotations\Assembler\Acceptor\AlwaysAcceptingAcceptor;
21
use PHPUnit\Framework\MockObject\MockObject;
22
use PHPUnit\Framework\TestCase;
23
24
final class MetadataCollectorTest extends TestCase
25
{
26
    /** @var AnnotationMetadataAssembler|MockObject */
27
    private $assembler;
28
29
    /** @var MetadataCollector */
30
    private $collector;
31
32
    protected function setUp() : void
33
    {
34
        $this->assembler = $this->createMock(AnnotationMetadataAssembler::class);
35
        $this->collector = new MetadataCollector(
36
            $this->assembler,
37
            new AlwaysAcceptingAcceptor(),
38
            new IdentifierPassingReferenceResolver()
39
        );
40
    }
41
42
    /**
43
     * @param callable(AnnotationMetadataAssembler) : void $initializer
44
     * @param callable(AnnotationMetadata[]) : void        $asserter
45
     *
46
     * @dataProvider docBlocksProvider()
47
     */
48
    public function testMetadata(Annotations $annotations, callable $initializer, callable $asserter) : void
49
    {
50
        $initializer($this->assembler);
51
52
        $collection = new MetadataCollection();
53
54
        $this->collector->collect($annotations, ScopeMother::example(), $collection);
55
56
        $asserter($collection);
57
    }
58
59
    public function docBlocksProvider() : iterable
60
    {
61
        yield 'single without parameters' => [
62
            new Annotations(
63
                new Annotation(
64
                    new Reference('Foo', true),
65
                    new Parameters()
66
                )
67
            ),
68
            function (MockObject $assembler) : void {
69
                /** @var AnnotationMetadataAssembler|MockObject $assembler */
70
                $assembler->method('assemble')
0 ignored issues
show
Bug introduced by
The method method() does not exist on Doctrine\Annotations\Met...tationMetadataAssembler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                $assembler->/** @scrutinizer ignore-call */ 
71
                            method('assemble')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                $assembler->/** @scrutinizer ignore-call */ 
71
                            method('assemble')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
                    ->with(
72
                        $this->callback(static function (Reference $reference) : bool {
73
                            return $reference->getIdentifier() === 'Foo' && $reference->isFullyQualified() === true;
74
                        }),
75
                        $this->isInstanceOf(Scope::class)
76
                    )
77
                    ->willReturn(new AnnotationMetadata(
78
                        'Foo',
79
                        new AnnotationTarget(AnnotationTarget::TARGET_ALL),
80
                        false,
81
                        []
82
                    ));
83
            },
84
            static function (MetadataCollection $collection) : void {
85
                self::assertCount(1, $collection);
86
                self::assertSame('Foo', $collection['Foo']->getName());
87
            },
88
        ];
89
        yield 'nested' => [
90
            new Annotations(
91
                new Annotation(
92
                    new Reference('Foo', true),
93
                    new Parameters(
94
                        new UnnamedParameter(
95
                            new Annotation(
96
                                new Reference('Bar', false),
97
                                new Parameters()
98
                            )
99
                        )
100
                    )
101
                )
102
            ),
103
            function (MockObject $assembler) : void {
104
                /** @var AnnotationMetadataAssembler|MockObject $assembler */
105
                $assembler->method('assemble')
106
                    ->withConsecutive(
107
                        [
108
                            $this->callback(static function (Reference $reference) : bool {
109
                                return $reference->getIdentifier() === 'Bar' && $reference->isFullyQualified() === false;
110
                            }),
111
                            $this->isInstanceOf(Scope::class),
112
                        ],
113
                        [
114
                            $this->callback(static function (Reference $reference) : bool {
115
                                return $reference->getIdentifier() === 'Foo' && $reference->isFullyQualified() === true;
116
                            }),
117
                            $this->isInstanceOf(Scope::class),
118
                        ]
119
                    )
120
                    ->willReturnOnConsecutiveCalls(
121
                        new AnnotationMetadata(
122
                            'Bar',
123
                            new AnnotationTarget(AnnotationTarget::TARGET_ALL),
124
                            false,
125
                            []
126
                        ),
127
                        new AnnotationMetadata(
128
                            'Foo',
129
                            new AnnotationTarget(AnnotationTarget::TARGET_ALL),
130
                            false,
131
                            []
132
                        )
133
                    );
134
            },
135
            static function (MetadataCollection $collection) : void {
136
                self::assertCount(2, $collection);
137
                self::assertSame('Bar', $collection['Bar']->getName());
138
                self::assertSame('Foo', $collection['Foo']->getName());
139
            }
140
        ];
141
    }
142
}
143