|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\C\Entity\Embeddable\Traits\Geo; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\DataTransferObjects\AbstractEntityUpdateDto; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Geo\HasAddressEmbeddableInterface; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Geo\AddressEmbeddableInterface; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo\AddressEmbeddable; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Geo\HasAddressEmbeddableTrait; |
|
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @large |
|
14
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Geo\HasAddressEmbeddableTrait |
|
15
|
|
|
*/ |
|
16
|
|
|
class HasAddressEmbeddableTraitLargeTest extends AbstractLargeTest |
|
17
|
|
|
{ |
|
18
|
|
|
public const WORK_DIR = self::VAR_PATH . |
|
19
|
|
|
'/' . |
|
20
|
|
|
self::TEST_TYPE_LARGE . |
|
21
|
|
|
'/HasAddressEmbeddableTraitLargeTest'; |
|
22
|
|
|
private const TEST_ENTITY = self::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Place'; |
|
23
|
|
|
protected static $buildOnce = true; |
|
24
|
|
|
private $entityFqn; |
|
25
|
|
|
|
|
26
|
|
|
public function setup() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
if (false === self::$built) { |
|
30
|
|
|
$this->getEntityGenerator()->generateEntity(self::TEST_ENTITY); |
|
31
|
|
|
$this->getEntityEmbeddableSetter() |
|
32
|
|
|
->setEntityHasEmbeddable(self::TEST_ENTITY, HasAddressEmbeddableTrait::class); |
|
33
|
|
|
} |
|
34
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
|
35
|
|
|
$this->recreateDtos(); |
|
36
|
|
|
$this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @test |
|
41
|
|
|
* @large |
|
42
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
43
|
|
|
*/ |
|
44
|
|
|
public function theEntityCanBeSavedAndLoadedWithCorrectValuesWithAnAssocArray(): void |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* @var HasAddressEmbeddableInterface $entity |
|
48
|
|
|
*/ |
|
49
|
|
|
$entity = $this->createEntity($this->entityFqn); |
|
50
|
|
|
$entity->update( |
|
51
|
|
|
new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto |
|
52
|
|
|
{ |
|
53
|
|
|
public function getAddressEmbeddable() |
|
54
|
|
|
{ |
|
55
|
|
|
return AddressEmbeddable::create( |
|
56
|
|
|
[ |
|
57
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NUMBER => '1', |
|
58
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_HOUSE_NAME => '', |
|
59
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_STREET => 'streetname', |
|
60
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_CITY => 'cityname', |
|
61
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_CODE => 'ABC 123', |
|
62
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_POSTAL_AREA => 'county', |
|
63
|
|
|
AddressEmbeddableInterface::EMBEDDED_PROP_COUNTRY_CODE => 'UK', |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$this->getEntitySaver()->save($entity); |
|
72
|
|
|
|
|
73
|
|
|
$loaded = $this->getRepositoryFactory() |
|
74
|
|
|
->getRepository($this->entityFqn) |
|
75
|
|
|
->findAll()[0]; |
|
76
|
|
|
self::assertSame($entity, $loaded); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @test |
|
81
|
|
|
* @large |
|
82
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Geo\HasAddressEmbeddableTrait |
|
83
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
84
|
|
|
*/ |
|
85
|
|
|
public function theEntityCanBeSavedAndLoadedWithCorrectValuesWithAnArray(): void |
|
86
|
|
|
{ |
|
87
|
|
|
/** |
|
88
|
|
|
* @var HasAddressEmbeddableInterface $entity |
|
89
|
|
|
*/ |
|
90
|
|
|
$entity = $this->createEntity($this->entityFqn); |
|
91
|
|
|
$entity->update( |
|
92
|
|
|
new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto |
|
93
|
|
|
{ |
|
94
|
|
|
public function getAddressEmbeddable() |
|
95
|
|
|
{ |
|
96
|
|
|
return AddressEmbeddable::create( |
|
97
|
|
|
[ |
|
98
|
|
|
'1', |
|
99
|
|
|
'', |
|
100
|
|
|
'streetname', |
|
101
|
|
|
'cityname', |
|
102
|
|
|
'ABC 123', |
|
103
|
|
|
'county', |
|
104
|
|
|
'UK', |
|
105
|
|
|
] |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
$this->getEntitySaver()->save($entity); |
|
113
|
|
|
|
|
114
|
|
|
$loaded = $this->getRepositoryFactory() |
|
115
|
|
|
->getRepository($this->entityFqn) |
|
116
|
|
|
->findAll()[0]; |
|
117
|
|
|
self::assertSame($entity, $loaded); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|