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
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
20
|
|
|
use Addiks\RDMBundle\Hydration\HydrationContextInterface; |
21
|
|
|
|
22
|
|
|
final class EntityMappingTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var EntityMapping |
27
|
|
|
*/ |
28
|
|
|
private $entityMapping; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var MappingInterface |
32
|
|
|
*/ |
33
|
|
|
private $fieldMappingA; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var MappingInterface |
37
|
|
|
*/ |
38
|
|
|
private $fieldMappingB; |
39
|
|
|
|
40
|
|
|
public function setUp(): void |
41
|
|
|
{ |
42
|
|
|
$this->fieldMappingA = $this->createMock(MappingInterface::class); |
|
|
|
|
43
|
|
|
$this->fieldMappingB = $this->createMock(MappingInterface::class); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->entityMapping = new EntityMapping(EntityExample::class, [ |
46
|
|
|
'fieldA' => $this->fieldMappingA, |
47
|
|
|
'fieldB' => $this->fieldMappingB, |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function shouldStoreEntityName() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals(EntityExample::class, $this->entityMapping->getEntityClassName()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function shouldStoreClassName() |
63
|
|
|
{ |
64
|
|
|
$this->assertEquals(EntityExample::class, $this->entityMapping->getClassName()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
*/ |
70
|
|
|
public function shouldHaveNoFactoryOrSerializer() |
71
|
|
|
{ |
72
|
|
|
$this->assertSame(null, $this->entityMapping->getFactory()); |
|
|
|
|
73
|
|
|
$this->assertSame(null, $this->entityMapping->getSerializer()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function shouldStoreFieldMappings() |
80
|
|
|
{ |
81
|
|
|
$this->assertEquals([ |
82
|
|
|
'fieldA' => $this->fieldMappingA, |
83
|
|
|
'fieldB' => $this->fieldMappingB, |
84
|
|
|
], $this->entityMapping->getFieldMappings()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @test |
89
|
|
|
*/ |
90
|
|
|
public function shouldDescribeOrigin() |
91
|
|
|
{ |
92
|
|
|
$this->assertEquals(EntityExample::class, $this->entityMapping->describeOrigin()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @test |
97
|
|
|
*/ |
98
|
|
|
public function shouldCollectColumns() |
99
|
|
|
{ |
100
|
|
|
$columnA = new Column("column_a", Type::getType("string"), []); |
101
|
|
|
$columnB = new Column("column_b", Type::getType("string"), []); |
102
|
|
|
|
103
|
|
|
/** @var array<Column> $expectedColumns */ |
104
|
|
|
$expectedColumns = [$columnA, $columnB]; |
105
|
|
|
|
106
|
|
|
$this->fieldMappingA->method('collectDBALColumns')->willReturn([$columnA]); |
|
|
|
|
107
|
|
|
$this->fieldMappingB->method('collectDBALColumns')->willReturn([$columnB]); |
108
|
|
|
|
109
|
|
|
$this->assertEquals($expectedColumns, $this->entityMapping->collectDBALColumns()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @test |
114
|
|
|
*/ |
115
|
|
|
public function shouldStoreDBALColumn() |
116
|
|
|
{ |
117
|
|
|
$this->assertNull($this->entityMapping->getDBALColumn()); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @test |
122
|
|
|
*/ |
123
|
|
|
public function shouldStoreId() |
124
|
|
|
{ |
125
|
|
|
$this->assertNull($this->entityMapping->getId()); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @test |
130
|
|
|
*/ |
131
|
|
|
public function shouldStoreReferenceId() |
132
|
|
|
{ |
133
|
|
|
$this->assertNull($this->entityMapping->getReferencedId()); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @test |
138
|
|
|
*/ |
139
|
|
|
public function shouldNotResolveValue() |
140
|
|
|
{ |
141
|
|
|
$this->assertEquals( |
142
|
|
|
[ |
143
|
|
|
'fieldA' => null, |
144
|
|
|
'fieldB' => null |
145
|
|
|
], |
146
|
|
|
$this->entityMapping->resolveValue( |
147
|
|
|
$this->createMock(HydrationContextInterface::class), |
148
|
|
|
[] |
149
|
|
|
) |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @test |
155
|
|
|
*/ |
156
|
|
|
public function shouldNotRevertValue() |
157
|
|
|
{ |
158
|
|
|
$this->assertEmpty($this->entityMapping->revertValue( |
159
|
|
|
$this->createMock(HydrationContextInterface::class), |
160
|
|
|
null |
161
|
|
|
)); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @test |
166
|
|
|
*/ |
167
|
|
|
public function shouldNotAssertValue() |
168
|
|
|
{ |
169
|
|
|
$this->assertNull($this->entityMapping->assertValue( |
|
|
|
|
170
|
|
|
$this->createMock(HydrationContextInterface::class), |
171
|
|
|
[], |
172
|
|
|
null |
173
|
|
|
)); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @test |
178
|
|
|
*/ |
179
|
|
|
public function shouldWakeUpInnerMapping() |
180
|
|
|
{ |
181
|
|
|
/** @var ContainerInterface $container */ |
182
|
|
|
$container = $this->createMock(ContainerInterface::class); |
183
|
|
|
|
184
|
|
|
$this->fieldMappingA->expects($this->once())->method("wakeUpMapping")->with( |
|
|
|
|
185
|
|
|
$this->equalTo($container) |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
$this->fieldMappingB->expects($this->once())->method("wakeUpMapping")->with( |
189
|
|
|
$this->equalTo($container) |
190
|
|
|
); |
191
|
|
|
|
192
|
|
|
$this->entityMapping->wakeUpMapping($container); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
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..