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); |
|
|
|
|
41
|
|
|
$this->fieldMappingB = $this->createMock(MappingInterface::class); |
|
|
|
|
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]); |
|
|
|
|
88
|
|
|
$this->fieldMappingB->method('collectDBALColumns')->willReturn([$columnB]); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$this->assertEquals($expectedColumns, $this->entityMapping->collectDBALColumns()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
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..