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\MetadataCollection; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use function iterator_to_array; |
12
|
|
|
|
13
|
|
|
final class MetadataCollectionTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testCollectionInterface() : void |
16
|
|
|
{ |
17
|
|
|
$foo = $this->createDummyMetadata('Foo'); |
18
|
|
|
$bar = $this->createDummyMetadata('Bar'); |
19
|
|
|
$baz = $this->createDummyMetadata('Baz'); |
20
|
|
|
|
21
|
|
|
$collection = new MetadataCollection(); |
22
|
|
|
|
23
|
|
|
self::assertCount(0, $collection); |
24
|
|
|
self::assertSame([], iterator_to_array($collection)); |
25
|
|
|
|
26
|
|
|
$collection->add($foo, $bar); |
27
|
|
|
|
28
|
|
|
self::assertCount(2, $collection); |
29
|
|
|
self::assertArrayHasKey('Foo', $collection); |
30
|
|
|
self::assertSame($foo, $collection['Foo']); |
31
|
|
|
self::assertArrayHasKey('Bar', $collection); |
32
|
|
|
self::assertSame($bar, $collection['Bar']); |
33
|
|
|
self::assertSame([$foo, $bar], iterator_to_array($collection)); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$collection[] = $baz; |
36
|
|
|
|
37
|
|
|
self::assertCount(3, $collection); |
|
|
|
|
38
|
|
|
self::assertArrayHasKey('Baz', $collection); |
39
|
|
|
self::assertSame($baz, $collection['Baz']); |
40
|
|
|
self::assertSame([$foo, $bar, $baz], iterator_to_array($collection)); |
41
|
|
|
|
42
|
|
|
unset($collection['Bar']); |
43
|
|
|
|
44
|
|
|
self::assertCount(2, $collection); |
45
|
|
|
self::assertArrayNotHasKey('Bar', $collection); |
46
|
|
|
self::assertSame([$foo, $baz], iterator_to_array($collection)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testMetadataInConstructor() : void |
50
|
|
|
{ |
51
|
|
|
self::assertCount(2, new MetadataCollection($this->createDummyMetadata('A'), $this->createDummyMetadata('B'))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function createDummyMetadata(string $name) : AnnotationMetadata |
55
|
|
|
{ |
56
|
|
|
return new AnnotationMetadata($name, AnnotationTarget::all(), false); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|