1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\RelationsGenerator; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\FakerData\String\BusinessIdentifierCodeFakerData; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\FakerData\String\CountryCodeFakerData; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\BusinessIdentifierCodeFieldTrait; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\CountryCodeFieldTrait; |
12
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class NamespaceHelperTest |
16
|
|
|
* |
17
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Small\CodeGeneration |
18
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper |
19
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper |
20
|
|
|
* @large |
21
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
22
|
|
|
*/ |
23
|
|
|
class NamespaceHelperTest extends AbstractTest |
24
|
|
|
{ |
25
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/NamespaceHelperTest'; |
26
|
|
|
|
27
|
|
|
public const TEST_ENTITY_FQN_BASE = self::TEST_PROJECT_ROOT_NAMESPACE . |
28
|
|
|
'\\' . |
29
|
|
|
AbstractGenerator::ENTITIES_FOLDER_NAME; |
30
|
|
|
|
31
|
|
|
public const TEST_ENTITIES = [ |
32
|
|
|
self::TEST_ENTITY_FQN_BASE . '\\Blah\\Foo', |
33
|
|
|
self::TEST_ENTITY_FQN_BASE . '\\Bar\\Baz', |
34
|
|
|
self::TEST_ENTITY_FQN_BASE . '\\No\\Relative', |
35
|
|
|
self::TEST_ENTITY_FQN_BASE . '\\Meh', |
36
|
|
|
self::TEST_ENTITY_FQN_BASE . '\\Nested\\Something\\Ho\\Hum', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
public const TEST_ENTITY_POST_CREATED = self::TEST_ENTITY_FQN_BASE . '\\Meh'; |
40
|
|
|
public const TEST_ENTITY_POST_CREATED_NESTED = self::TEST_ENTITY_FQN_BASE . '\\Nested\\Something\\Ho\\Hum'; |
41
|
|
|
protected static $buildOnce = true; |
42
|
|
|
/** |
43
|
|
|
* @var NamespaceHelper |
44
|
|
|
*/ |
45
|
|
|
private static $helper; |
46
|
|
|
|
47
|
|
|
public function setup() |
48
|
|
|
{ |
49
|
|
|
parent::setUp(); |
50
|
|
|
if (true === self::$built) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
$entityGenerator = $this->getEntityGenerator(); |
54
|
|
|
$relationsGenerator = $this->getRelationsGenerator(); |
55
|
|
|
foreach (self::TEST_ENTITIES as $fqn) { |
56
|
|
|
$entityGenerator->generateEntity($fqn); |
57
|
|
|
$relationsGenerator->generateRelationCodeForEntity($fqn); |
58
|
|
|
} |
59
|
|
|
$relationsGenerator->setEntityHasRelationToEntity( |
60
|
|
|
self::TEST_ENTITIES[0], |
61
|
|
|
RelationsGenerator::HAS_MANY_TO_MANY, |
62
|
|
|
self::TEST_ENTITIES[1] |
63
|
|
|
); |
64
|
|
|
self::$built = true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function setupBeforeClass() |
68
|
|
|
{ |
69
|
|
|
parent::setUpBeforeClass(); |
70
|
|
|
self::$helper = new NamespaceHelper(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
* @large |
76
|
|
|
* */ |
77
|
|
|
public function getObjectShortName(): void |
78
|
|
|
{ |
79
|
|
|
|
80
|
|
|
$expectedToObjects = [ |
81
|
|
|
'NamespaceHelperTest' => $this, |
82
|
|
|
'NamespaceHelper' => self::$helper, |
83
|
|
|
]; |
84
|
|
|
$actual = []; |
85
|
|
|
foreach ($expectedToObjects as $object) { |
86
|
|
|
$actual[self::$helper->getObjectShortName($object)] = $object; |
87
|
|
|
} |
88
|
|
|
self::assertSame($expectedToObjects, $actual); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @test |
93
|
|
|
* @large |
94
|
|
|
* */ |
95
|
|
|
public function getObjectFqn(): void |
96
|
|
|
{ |
97
|
|
|
|
98
|
|
|
$expectedToObjects = [ |
99
|
|
|
\get_class($this) => $this, |
100
|
|
|
\get_class(self::$helper) => self::$helper, |
101
|
|
|
]; |
102
|
|
|
$actual = []; |
103
|
|
|
foreach ($expectedToObjects as $object) { |
104
|
|
|
$actual[self::$helper->getObjectFqn($object)] = $object; |
105
|
|
|
} |
106
|
|
|
self::assertSame($expectedToObjects, $actual); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @test |
111
|
|
|
* @large |
112
|
|
|
* */ |
113
|
|
|
public function getClassShortName(): void |
114
|
|
|
{ |
115
|
|
|
$expectedToFqns = [ |
116
|
|
|
'NamespaceHelperTest' => \get_class($this), |
117
|
|
|
'Cheese' => '\\Super\\Cheese', |
118
|
|
|
]; |
119
|
|
|
$actual = []; |
120
|
|
|
foreach ($expectedToFqns as $fqn) { |
121
|
|
|
$actual[self::$helper->getClassShortName($fqn)] = $fqn; |
122
|
|
|
} |
123
|
|
|
self::assertSame($expectedToFqns, $actual); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @test |
132
|
|
|
* @large |
133
|
|
|
*/ |
134
|
|
|
public function testCalculateProjectNamespaceRootFromEntitFqn(): void |
135
|
|
|
{ |
136
|
|
|
$entity1Fqn = self::TEST_ENTITIES[0]; |
137
|
|
|
|
138
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE; |
139
|
|
|
$actual = self::$helper->getProjectNamespaceRootFromEntityFqn($entity1Fqn); |
140
|
|
|
self::assertSame($expected, $actual); |
141
|
|
|
|
142
|
|
|
$entityFqnWithEntitiesInProjectName = self::TEST_ENTITIES[0]; |
143
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE; |
144
|
|
|
$actual = self::$helper->getProjectNamespaceRootFromEntityFqn( |
145
|
|
|
$entityFqnWithEntitiesInProjectName |
146
|
|
|
); |
147
|
|
|
self::assertSame($expected, $actual); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
152
|
|
|
*/ |
153
|
|
|
public function testParseFullyQualifiedName(): void |
154
|
|
|
{ |
155
|
|
|
$entity1Fqn = self::TEST_ENTITIES[0]; |
156
|
|
|
$srcOrTestSubFolder = 'src'; |
157
|
|
|
$projectRootNamespace = self::TEST_PROJECT_ROOT_NAMESPACE; |
158
|
|
|
$expected = [ |
159
|
|
|
'Foo', |
160
|
|
|
$projectRootNamespace . '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME . '\\Blah', |
161
|
|
|
[ |
162
|
|
|
'src', |
163
|
|
|
'Entities', |
164
|
|
|
'Blah', |
165
|
|
|
], |
166
|
|
|
]; |
167
|
|
|
$actual = self::$helper->parseFullyQualifiedName( |
168
|
|
|
$entity1Fqn, |
169
|
|
|
$srcOrTestSubFolder, |
170
|
|
|
$projectRootNamespace |
171
|
|
|
); |
172
|
|
|
self::assertSame($expected, $actual); |
173
|
|
|
|
174
|
|
|
$srcOrTestSubFolder = 'src'; |
175
|
|
|
$projectRootNamespace = '\\' . self::TEST_PROJECT_ROOT_NAMESPACE; |
176
|
|
|
$expected = [ |
177
|
|
|
'Foo', |
178
|
|
|
ltrim($projectRootNamespace . '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME . '\\Blah', '\\'), |
179
|
|
|
[ |
180
|
|
|
'src', |
181
|
|
|
'Entities', |
182
|
|
|
'Blah', |
183
|
|
|
], |
184
|
|
|
]; |
185
|
|
|
$actual = self::$helper->parseFullyQualifiedName( |
186
|
|
|
self::TEST_ENTITIES[0], |
187
|
|
|
$srcOrTestSubFolder, |
188
|
|
|
$projectRootNamespace |
189
|
|
|
); |
190
|
|
|
self::assertSame($expected, $actual); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @test |
195
|
|
|
* @large |
196
|
|
|
*/ |
197
|
|
|
public function testCalculcateOwnedHasName(): void |
198
|
|
|
{ |
199
|
|
|
$hasType = RelationsGenerator::HAS_MANY_TO_MANY; |
200
|
|
|
$ownedEntityFqn = self::TEST_ENTITIES[0]; |
201
|
|
|
$expected = 'BlahFoos'; |
202
|
|
|
$srcOrTestSubFolder = 'src'; |
203
|
|
|
$projectRootNamespace = '\\' . self::TEST_PROJECT_ROOT_NAMESPACE; |
204
|
|
|
|
205
|
|
|
$actual = self::$helper->getOwnedHasName( |
206
|
|
|
$hasType, |
207
|
|
|
$ownedEntityFqn, |
208
|
|
|
$srcOrTestSubFolder, |
209
|
|
|
$projectRootNamespace |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
self::assertSame($expected, $actual); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @test |
217
|
|
|
* @large |
218
|
|
|
*/ |
219
|
|
|
public function testGetEntitySubNamespace(): void |
220
|
|
|
{ |
221
|
|
|
$entityFqn = self::TEST_ENTITIES[0]; |
222
|
|
|
$expected = 'Blah\\Foo'; |
223
|
|
|
$actual = self::$helper->getEntitySubNamespace($entityFqn); |
224
|
|
|
self::assertSame($expected, $actual); |
225
|
|
|
|
226
|
|
|
$entityFqn = '\\My\\Test\\Project\\Entities\\No\\Relatives'; |
227
|
|
|
$expected = 'No\\Relatives'; |
228
|
|
|
$actual = self::$helper->getEntitySubNamespace($entityFqn); |
229
|
|
|
self::assertSame($expected, $actual); |
230
|
|
|
|
231
|
|
|
$entityFqn = '\\My\\Test\\Project\\Entities\\Person'; |
232
|
|
|
$expected = 'Person'; |
233
|
|
|
$actual = self::$helper->getEntitySubNamespace($entityFqn); |
234
|
|
|
self::assertSame($expected, $actual); |
235
|
|
|
|
236
|
|
|
$entityFqn = '\\My\\Test\\EntitiesProject\\Entities\\Person'; |
237
|
|
|
$expected = 'Person'; |
238
|
|
|
$actual = self::$helper->getEntitySubNamespace($entityFqn); |
239
|
|
|
self::assertSame($expected, $actual); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @test |
244
|
|
|
* @large |
245
|
|
|
*/ |
246
|
|
|
public function testGetEntitySubFilePath(): void |
247
|
|
|
{ |
248
|
|
|
$entityFqn = '\\My\\Test\\Project\\Entities\\Person'; |
249
|
|
|
$expected = '/Person.php'; |
250
|
|
|
$actual = self::$helper->getEntityFileSubPath($entityFqn); |
251
|
|
|
self::assertSame($expected, $actual); |
252
|
|
|
|
253
|
|
|
$entityFqn = '\\My\\Test\\EntitiesProject\\Entities\\Person'; |
254
|
|
|
$expected = '/Person.php'; |
255
|
|
|
$actual = self::$helper->getEntityFileSubPath($entityFqn); |
256
|
|
|
self::assertSame($expected, $actual); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @test |
261
|
|
|
* @large |
262
|
|
|
*/ |
263
|
|
|
public function testGetEntitySubPath(): void |
264
|
|
|
{ |
265
|
|
|
$entityFqn = self::TEST_ENTITIES[0]; |
266
|
|
|
$expected = '/Blah/Foo'; |
267
|
|
|
$actual = self::$helper->getEntitySubPath($entityFqn); |
268
|
|
|
self::assertSame($expected, $actual); |
269
|
|
|
|
270
|
|
|
$entityFqn = '\\My\\Test\\EntitiesProject\\Entities\\Person'; |
271
|
|
|
$expected = '/Person'; |
272
|
|
|
$actual = self::$helper->getEntitySubPath($entityFqn); |
273
|
|
|
self::assertSame($expected, $actual); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @test |
278
|
|
|
* @large |
279
|
|
|
*/ |
280
|
|
|
public function testGetInterfacesNamespaceForEntity(): void |
281
|
|
|
{ |
282
|
|
|
$entityFqn = self::TEST_ENTITIES[0]; |
283
|
|
|
$entityRelationsRootNamespace = self::TEST_PROJECT_ROOT_NAMESPACE |
284
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE; |
285
|
|
|
$expected = $entityRelationsRootNamespace . '\\Blah\\Foo\\Interfaces'; |
286
|
|
|
$actual = self::$helper->getInterfacesNamespaceForEntity($entityFqn); |
287
|
|
|
self::assertSame($expected, $actual); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @test |
292
|
|
|
* @large |
293
|
|
|
*/ |
294
|
|
|
public function testGetTraitsNamespaceForEntity(): void |
295
|
|
|
{ |
296
|
|
|
$entityFqn = self::TEST_ENTITIES[0]; |
297
|
|
|
$entityRelationsRootNamespace = self::TEST_PROJECT_ROOT_NAMESPACE |
298
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE; |
299
|
|
|
$expected = $entityRelationsRootNamespace . '\\Blah\\Foo\\Traits'; |
300
|
|
|
$actual = self::$helper->getTraitsNamespaceForEntity($entityFqn); |
301
|
|
|
self::assertSame($expected, $actual); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @test |
308
|
|
|
* @large |
309
|
|
|
*/ |
310
|
|
|
public function testGetHasPluralInterfaceFqnForEntity(): void |
311
|
|
|
{ |
312
|
|
|
$entityFqn = self::TEST_ENTITY_POST_CREATED; |
313
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE |
314
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE |
315
|
|
|
. '\\Meh\\Interfaces\\HasMehsInterface'; |
316
|
|
|
$actual = self::$helper->getHasPluralInterfaceFqnForEntity($entityFqn); |
317
|
|
|
self::assertSame($expected, $actual); |
318
|
|
|
|
319
|
|
|
$entityFqn = self::TEST_ENTITY_POST_CREATED_NESTED; |
320
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE |
321
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE |
322
|
|
|
. '\\Nested\\Something\\Ho\\Hum\\Interfaces\\HasNestedSomethingHoHumsInterface'; |
323
|
|
|
$actual = self::$helper->getHasPluralInterfaceFqnForEntity($entityFqn); |
324
|
|
|
self::assertSame($expected, $actual); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @test |
329
|
|
|
* @large |
330
|
|
|
*/ |
331
|
|
|
public function testgetHasSingularInterfaceFqnForEntity(): void |
332
|
|
|
{ |
333
|
|
|
$entityFqn = self::TEST_ENTITY_POST_CREATED; |
334
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE |
335
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE |
336
|
|
|
. '\\Meh\\Interfaces\\HasMehInterface'; |
337
|
|
|
$actual = self::$helper->getHasSingularInterfaceFqnForEntity($entityFqn); |
338
|
|
|
self::assertSame($expected, $actual); |
339
|
|
|
|
340
|
|
|
$entityFqn = self::TEST_ENTITY_POST_CREATED_NESTED; |
341
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE |
342
|
|
|
. AbstractGenerator::ENTITY_RELATIONS_NAMESPACE |
343
|
|
|
. '\\Nested\\Something\\Ho\\Hum\\Interfaces\\HasNestedSomethingHoHumInterface'; |
344
|
|
|
$actual = self::$helper->getHasSingularInterfaceFqnForEntity($entityFqn); |
345
|
|
|
self::assertSame($expected, $actual); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
350
|
|
|
*/ |
351
|
|
|
public function testGetProjectRootNamespaceFromComposerJson(): void |
352
|
|
|
{ |
353
|
|
|
$expected = 'EdmondsCommerce\\DoctrineStaticMeta'; |
354
|
|
|
$actual = self::$helper->getProjectRootNamespaceFromComposerJson(); |
355
|
|
|
self::assertSame($expected, $actual); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @test |
360
|
|
|
* @large |
361
|
|
|
*/ |
362
|
|
|
public function testStripPrefixFromHasType(): void |
363
|
|
|
{ |
364
|
|
|
$expected = [ |
365
|
|
|
'OwningOneToOne' => 'OwningOneToOne', |
366
|
|
|
'InverseOneToOne' => 'InverseOneToOne', |
367
|
|
|
'UnidirectionalOneToOne' => 'UnidirectionalOneToOne', |
368
|
|
|
'OneToMany' => 'OneToMany', |
369
|
|
|
'UnidirectionalOneToMany' => 'UnidirectionalOneToMany', |
370
|
|
|
'ManyToOne' => 'ManyToOne', |
371
|
|
|
'UnidirectionalManyToOne' => 'UnidirectionalManyToOne', |
372
|
|
|
'OwningManyToMany' => 'OwningManyToMany', |
373
|
|
|
'InverseManyToMany' => 'InverseManyToMany', |
374
|
|
|
]; |
375
|
|
|
$actual = []; |
376
|
|
|
foreach (RelationsGenerator::HAS_TYPES as $hasType) { |
377
|
|
|
$actual[$hasType] = self::$helper->stripPrefixFromHasType($hasType); |
378
|
|
|
} |
379
|
|
|
self::assertSame($expected, $actual); |
380
|
|
|
foreach ($actual as $hasType => $stripped) { |
381
|
|
|
$ownedHasName = self::$helper->getOwnedHasName( |
382
|
|
|
$hasType, |
383
|
|
|
"\\TemplateNamespace\\Entities\\TemplateEntity", |
384
|
|
|
'src', |
385
|
|
|
'\\TemplateNamespace' |
386
|
|
|
); |
387
|
|
|
$filePath = realpath(AbstractGenerator::TEMPLATE_PATH) |
388
|
|
|
. '/src/Entity/Relations/TemplateEntity/Traits/Has' |
389
|
|
|
. $ownedHasName . '/Has' . $ownedHasName . $stripped . '.php'; |
390
|
|
|
$longestExisting = ''; |
391
|
|
|
foreach (explode('/', $filePath) as $part) { |
392
|
|
|
$maybeLongestExisting = $longestExisting . '/' . $part; |
393
|
|
|
if (is_file($maybeLongestExisting) || is_dir($maybeLongestExisting)) { |
394
|
|
|
$longestExisting = $maybeLongestExisting; |
395
|
|
|
continue; |
396
|
|
|
} |
397
|
|
|
break; |
398
|
|
|
} |
399
|
|
|
$longestExisting = substr($longestExisting, 1); |
400
|
|
|
self::assertFileExists($filePath, "\n$filePath\nexists up to:\n$longestExisting\n"); |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* @test |
406
|
|
|
* @large |
407
|
|
|
*/ |
408
|
|
|
public function testGetOwningTraitFqn(): void |
409
|
|
|
{ |
410
|
|
|
$traitBase = '\\TemplateNamespace\\Entity\Relations\\TemplateEntity\\Traits'; |
411
|
|
|
$expected = [ |
412
|
|
|
'OwningOneToOne' => $traitBase . '\\HasTemplateEntity\\HasTemplateEntityOwningOneToOne', |
413
|
|
|
'InverseOneToOne' => $traitBase . '\\HasTemplateEntity\\HasTemplateEntityInverseOneToOne', |
414
|
|
|
'UnidirectionalOneToOne' => $traitBase . '\\HasTemplateEntity\\HasTemplateEntityUnidirectionalOneToOne', |
415
|
|
|
'OneToMany' => $traitBase . '\\HasTemplateEntities\\HasTemplateEntitiesOneToMany', |
416
|
|
|
'UnidirectionalOneToMany' => $traitBase . |
417
|
|
|
'\\HasTemplateEntities\\HasTemplateEntitiesUnidirectionalOneToMany', |
418
|
|
|
'ManyToOne' => $traitBase . '\\HasTemplateEntity\\HasTemplateEntityManyToOne', |
419
|
|
|
'UnidirectionalManyToOne' => $traitBase . '\\HasTemplateEntity\\HasTemplateEntityUnidirectionalManyToOne', |
420
|
|
|
'OwningManyToMany' => $traitBase . '\\HasTemplateEntities\\HasTemplateEntitiesOwningManyToMany', |
421
|
|
|
'InverseManyToMany' => $traitBase . '\\HasTemplateEntities\\HasTemplateEntitiesInverseManyToMany', |
422
|
|
|
]; |
423
|
|
|
$actual = []; |
424
|
|
|
foreach (RelationsGenerator::HAS_TYPES as $hasType) { |
425
|
|
|
$actual[$hasType] = self::$helper->getOwningTraitFqn( |
426
|
|
|
$hasType, |
427
|
|
|
"\\TemplateNamespace\\Entities\\TemplateEntity", |
428
|
|
|
"\\TemplateNamespace" |
429
|
|
|
); |
430
|
|
|
} |
431
|
|
|
self::assertSame( |
432
|
|
|
$expected, |
433
|
|
|
$actual, |
434
|
|
|
"\nExpected:\n" . var_export($actual, true) |
435
|
|
|
. "\nActual:\n" . var_export($actual, true) . "\n" |
436
|
|
|
); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @test |
441
|
|
|
* @large |
442
|
|
|
*/ |
443
|
|
|
public function testGetOwningInterfaceFqn(): void |
444
|
|
|
{ |
445
|
|
|
$intBase = '\\TemplateNamespace\\Entity\Relations\\TemplateEntity\\Interfaces'; |
446
|
|
|
$expected = [ |
447
|
|
|
'OwningOneToOne' => $intBase . '\\HasTemplateEntityInterface', |
448
|
|
|
'InverseOneToOne' => $intBase . '\\HasTemplateEntityInterface', |
449
|
|
|
'UnidirectionalOneToOne' => $intBase . '\\HasTemplateEntityInterface', |
450
|
|
|
'OneToMany' => $intBase . '\\HasTemplateEntitiesInterface', |
451
|
|
|
'UnidirectionalOneToMany' => $intBase . '\\HasTemplateEntitiesInterface', |
452
|
|
|
'ManyToOne' => $intBase . '\\HasTemplateEntityInterface', |
453
|
|
|
'UnidirectionalManyToOne' => $intBase . '\\HasTemplateEntityInterface', |
454
|
|
|
'OwningManyToMany' => $intBase . '\\HasTemplateEntitiesInterface', |
455
|
|
|
'InverseManyToMany' => $intBase . '\\HasTemplateEntitiesInterface', |
456
|
|
|
]; |
457
|
|
|
$actual = []; |
458
|
|
|
foreach (RelationsGenerator::HAS_TYPES as $hasType) { |
459
|
|
|
$actual[$hasType] = self::$helper->getOwningInterfaceFqn( |
460
|
|
|
$hasType, |
461
|
|
|
"\\TemplateNamespace\\Entities\\TemplateEntity", |
462
|
|
|
"\\TemplateNamespace" |
463
|
|
|
); |
464
|
|
|
} |
465
|
|
|
self::assertSame( |
466
|
|
|
$expected, |
467
|
|
|
$actual, |
468
|
|
|
"\nExpected:\n" . var_export($actual, true) |
469
|
|
|
. "\nActual:\n" . var_export($actual, true) . "\n" |
470
|
|
|
); |
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
|