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

createAnnotationTargetAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations;
6
7
use Doctrine\Annotations\Annotation;
8
use Doctrine\Annotations\Metadata\MetadataCollection;
9
use Doctrine\Annotations\Metadata\Reflection\DefaultReflectionProvider;
10
use Doctrine\Annotations\NewAnnotationReader;
11
use Doctrine\Tests\Annotations\Fixtures\AnnotationTargetAll;
12
use Doctrine\Tests\Annotations\Fixtures\ClassWithAnnotationTargetAll;
13
use PHPUnit\Framework\TestCase;
14
use ReflectionClass;
15
16
class NewAnnotationReaderTest extends TestCase
17
{
18
    /** @var MetadataCollection */
19
    private $collection;
20
21
    /** @var NewAnnotationReader */
22
    private $reader;
23
24
    public function setUp() : void
25
    {
26
        $this->collection = new MetadataCollection();
27
        $this->reader     = new NewAnnotationReader(
28
            $this->collection,
29
            new DefaultReflectionProvider()
30
        );
31
    }
32
33
    /**
34
     * @param Annotation[] $expected
35
     *
36
     * @dataProvider examples
37
     */
38
    public function testGetClassAnnotations(string $class, array $expected) : void
39
    {
40
        $class = new ReflectionClass($class);
41
42
        $annotations = $this->reader->getClassAnnotations($class);
43
44
        $this->assertEquals(
45
            $expected,
46
            $annotations
47
        );
48
    }
49
50
    /**
51
     * @return mixed[]
52
     */
53
    public function examples() : iterable
54
    {
55
        yield 'ClassWithAnnotationTargetAll' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'ClassWithAnnotati...ationTargetAll('123'))) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
56
            ClassWithAnnotationTargetAll::class,
57
            [$this->createAnnotationTargetAll('123')],
58
        ];
59
    }
60
61
    private function createAnnotationTargetAll(?string $name = null) : AnnotationTargetAll
62
    {
63
        $annotation = new AnnotationTargetAll();
64
65
        $annotation->name = $name;
66
67
        return $annotation;
68
    }
69
}
70