testGetEntityMetadataWithInvalidClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\DoctrineDDMTest\Unit\Configuration;
6
7
use Facile\DoctrineDDM\Configuration\EntityMetadata;
8
use Facile\DoctrineDDM\Configuration\Metadata;
9
use Facile\DoctrineDDM\Exception\InvalidArgumentException;
10
use Facile\DoctrineDDMTest\Framework\TestCase;
11
12
class MetadataTest extends TestCase
13
{
14
    public function testConstructor()
15
    {
16
        $metadata = new Metadata();
17
18
        $this->assertEquals([], $metadata->getEntityMetadatas());
19
        $this->assertNull($metadata->getEntityMetadata('foo'));
20
    }
21
22
    public function testSetEntities()
23
    {
24
        $metadata = new Metadata();
25
26
        $fooEntityMetadata = $this->prophesize(EntityMetadata::class);
27
        $fooEntityMetadata->getEntityClass()->willReturn('foo');
28
29
        $barEntityMetadata = $this->prophesize(EntityMetadata::class);
30
        $barEntityMetadata->getEntityClass()->willReturn('bar');
31
32
        $metadata->setEntityMetadatas([
33
            $fooEntityMetadata->reveal(),
34
            $barEntityMetadata->reveal(),
35
        ]);
36
37
        $expected = [
38
            'foo' => $fooEntityMetadata->reveal(),
39
            'bar' => $barEntityMetadata->reveal(),
40
        ];
41
42
        $this->assertEquals($expected, $metadata->getEntityMetadatas());
43
    }
44
45
    public function testAddEntityMetadata()
46
    {
47
        $this->expectException(InvalidArgumentException::class);
48
        $this->expectExceptionMessage('Entity "foo" is already defined');
49
50
        $metadata = new Metadata();
51
52
        $fooEntityMetadata1 = $this->prophesize(EntityMetadata::class);
53
        $fooEntityMetadata1->getEntityClass()->willReturn('foo');
54
55
        $fooEntityMetadata2 = $this->prophesize(EntityMetadata::class);
56
        $fooEntityMetadata2->getEntityClass()->willReturn('foo');
57
58
        $metadata->addEntityMetadata($fooEntityMetadata1->reveal());
59
        $metadata->addEntityMetadata($fooEntityMetadata2->reveal());
60
    }
61
62
    public function testGetEntityMetadata()
63
    {
64
        $metadata = new Metadata();
65
66
        $fooEntityMetadata = $this->prophesize(EntityMetadata::class);
67
        $fooEntityMetadata->getEntityClass()->willReturn('foo');
68
69
        $metadata->setEntityMetadatas([
70
            $fooEntityMetadata->reveal(),
71
        ]);
72
73
        $this->assertSame($fooEntityMetadata->reveal(), $metadata->getEntityMetadata('foo'));
74
    }
75
76
    public function testGetEntityMetadataWithInvalidClass()
77
    {
78
        $metadata = new Metadata();
79
80
        $this->assertNull($metadata->getEntityMetadata('foo'));
81
    }
82
}
83