|
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' => [ |
|
|
|
|
|
|
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
|
|
|
|