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

MetadataCollectorTest::docBlocksProvider()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 78
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 78
rs 9.1127
c 0
b 0
f 0
cc 4
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Reference\StaticReferenceResolver;
18
use Doctrine\Annotations\Parser\Scope;
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->markTestIncomplete('Collector has incorrect setup');
35
36
        $this->assembler = $this->createMock(AnnotationMetadataAssembler::class);
37
        $this->collector = new MetadataCollector(
38
            $this->assembler,
39
            new AlwaysAcceptingAcceptor(),
40
            new StaticReferenceResolver()
41
        );
42
    }
43
44
    /**
45
     * @param callable(AnnotationMetadataAssembler) : void $initializer
46
     * @param callable(AnnotationMetadata[]) : void        $asserter
47
     *
48
     * @dataProvider docBlocksProvider()
49
     */
50
    public function testMetadata(Annotations $annotations, callable $initializer, callable $asserter) : void
51
    {
52
        $initializer($this->assembler);
53
54
        $collection = new MetadataCollection();
55
56
        $this->collector->collect($annotations, ScopeMother::example(), $collection);
57
58
        $asserter(...$collection);
59
    }
60
61
    public function docBlocksProvider() : iterable
62
    {
63
        yield 'single without parameters' => [
64
            new Annotations(
65
                new Annotation(
66
                    new Reference('Foo', true),
67
                    new Parameters()
68
                )
69
            ),
70
            function (AnnotationMetadataAssembler $assembler) : void {
71
                $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

71
                $assembler->/** @scrutinizer ignore-call */ 
72
                            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...
72
                    ->with(
73
                        $this->callback(static function (Reference $reference) : bool {
74
                            return $reference->getIdentifier() === 'Foo' && $reference->isFullyQualified() === true;
75
                        }),
76
                        $this->isInstanceOf(Scope::class)
77
                    )
78
                    ->willReturn(new AnnotationMetadata(
79
                        'Foo',
80
                        new AnnotationTarget(AnnotationTarget::TARGET_ALL),
81
                        false,
82
                        []
83
                    ));
84
            },
85
            static function (AnnotationMetadata ...$metadatas) : void {
86
                self::assertCount(1, $metadatas);
87
                self::assertSame('Foo', $metadatas[0]->getName());
88
            },
89
        ];
90
        yield 'nested' => [
91
            new Annotations(
92
                new Annotation(
93
                    new Reference('Foo', true),
94
                    new Parameters(
95
                        new UnnamedParameter(
96
                            new Annotation(
97
                                new Reference('Bar', false),
98
                                new Parameters()
99
                            )
100
                        )
101
                    )
102
                )
103
            ),
104
            function (AnnotationMetadataAssembler $assembler) : void {
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 (AnnotationMetadata ...$metadatas) : void {
136
                self::assertCount(2, $metadatas);
137
                self::assertSame('Bar', $metadatas[0]->getName());
138
                self::assertSame('Foo', $metadatas[1]->getName());
139
            },
140
        ];
141
    }
142
}
143