Completed
Push — master ( 7e6070...203e38 )
by Gerrit
02:38
created

EntityMappingTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Tests\Mapping;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Mapping\EntityMapping;
15
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
16
use Doctrine\DBAL\Schema\Column;
17
use Doctrine\DBAL\Types\Type;
18
use Addiks\RDMBundle\Mapping\MappingInterface;
19
20
final class EntityMappingTest extends TestCase
21
{
22
23
    /**
24
     * @var EntityMapping
25
     */
26
    private $entityMapping;
27
28
    /**
29
     * @var MappingInterface
30
     */
31
    private $fieldMappingA;
32
33
    /**
34
     * @var MappingInterface
35
     */
36
    private $fieldMappingB;
37
38
    public function setUp()
39
    {
40
        $this->fieldMappingA = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $fieldMappingA.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        $this->fieldMappingB = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $fieldMappingB.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42
43
        $this->entityMapping = new EntityMapping(EntityExample::class, [
44
            $this->fieldMappingA,
45
            $this->fieldMappingB,
46
        ]);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function shouldStoreEntityName()
53
    {
54
        $this->assertEquals(EntityExample::class, $this->entityMapping->getEntityClassName());
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function shouldStoreFieldMappings()
61
    {
62
        $this->assertEquals([
63
            $this->fieldMappingA,
64
            $this->fieldMappingB,
65
        ], $this->entityMapping->getFieldMappings());
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function shouldDescribeOrigin()
72
    {
73
        $this->assertEquals(EntityExample::class, $this->entityMapping->describeOrigin());
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function shouldCollectColumns()
80
    {
81
        $columnA = new Column("column_a", Type::getType("string"), []);
82
        $columnB = new Column("column_b", Type::getType("string"), []);
83
84
        /** @var array<Column> $expectedColumns */
85
        $expectedColumns = [$columnA, $columnB];
86
87
        $this->fieldMappingA->method('collectDBALColumns')->willReturn([$columnA]);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
        $this->fieldMappingB->method('collectDBALColumns')->willReturn([$columnB]);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
90
        $this->assertEquals($expectedColumns, $this->entityMapping->collectDBALColumns());
91
    }
92
93
}
94