Failed Conditions
Push — metadata ( 75cc1c...c6c11e )
by Michael
01:50
created

MetadataCollectionTest::testCollectionInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 32
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 0
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));
0 ignored issues
show
Bug introduced by
$collection of type ArrayAccess|array is incompatible with the type Traversable expected by parameter $iterator of iterator_to_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        self::assertSame([$foo, $bar], iterator_to_array(/** @scrutinizer ignore-type */ $collection));
Loading history...
34
35
        $collection[] = $baz;
36
37
        self::assertCount(3, $collection);
0 ignored issues
show
Bug introduced by
It seems like $collection can also be of type ArrayAccess; however, parameter $haystack of PHPUnit\Framework\Assert::assertCount() does only seem to accept Countable|iterable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        self::assertCount(3, /** @scrutinizer ignore-type */ $collection);
Loading history...
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