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

NewAnnotationReaderTest::testGetClassAnnotations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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