1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Medium; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo\AddressEmbeddable; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity\FullNameEmbeddable; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
12
|
|
|
use ts\Reflection\ReflectionClass; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta |
16
|
|
|
* @medium |
17
|
|
|
*/ |
18
|
|
|
class DoctrineStaticMetaTest extends AbstractTest |
19
|
|
|
{ |
20
|
|
|
public const WORK_DIR = self::VAR_PATH . '/' . self::TEST_TYPE_MEDIUM . '/DoctrineStaticMetaTest'; |
21
|
|
|
|
22
|
|
|
private const TEST_ENTITY_FQN = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_PERSON; |
23
|
|
|
|
24
|
|
|
protected static $buildOnce = true; |
25
|
|
|
|
26
|
|
|
public function setup() |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
if (false === self::$built) { |
30
|
|
|
$this->getTestCodeGenerator() |
31
|
|
|
->copyTo(self::WORK_DIR); |
32
|
|
|
self::$built = true; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function itCanGetGetters(): void |
40
|
|
|
{ |
41
|
|
|
$expected = [ |
42
|
|
|
'getId', |
43
|
|
|
'getUuid', |
44
|
|
|
'getString', |
45
|
|
|
'getDatetime', |
46
|
|
|
'getFloat', |
47
|
|
|
'getDecimal', |
48
|
|
|
'getInteger', |
49
|
|
|
'getText', |
50
|
|
|
'isBoolean', |
51
|
|
|
'getJson', |
52
|
|
|
'getAttributesAddress', |
53
|
|
|
'getAttributesEmails', |
54
|
|
|
'getCompanyDirector', |
55
|
|
|
'getLargeRelation', |
56
|
|
|
]; |
57
|
|
|
$actual = $this->getDsm()->getGetters(); |
58
|
|
|
self::assertSame($expected, $actual); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function getDsm($entityFqn = self::TEST_ENTITY_FQN): DoctrineStaticMeta |
62
|
|
|
{ |
63
|
|
|
return new DoctrineStaticMeta($entityFqn); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @test |
68
|
|
|
*/ |
69
|
|
|
public function itCanGetSetters(): void |
70
|
|
|
{ |
71
|
|
|
$expected = [ |
72
|
|
|
'getId' => 'setId', |
73
|
|
|
'getString' => 'setString', |
74
|
|
|
'getDatetime' => 'setDatetime', |
75
|
|
|
'getFloat' => 'setFloat', |
76
|
|
|
'getDecimal' => 'setDecimal', |
77
|
|
|
'getInteger' => 'setInteger', |
78
|
|
|
'getText' => 'setText', |
79
|
|
|
'isBoolean' => 'setBoolean', |
80
|
|
|
'getJson' => 'setJson', |
81
|
|
|
'getAttributesAddress' => 'setAttributesAddress', |
82
|
|
|
'getAttributesEmails' => 'setAttributesEmails', |
83
|
|
|
'getCompanyDirector' => 'setCompanyDirector', |
84
|
|
|
'getLargeRelation' => 'setLargeRelation', |
85
|
|
|
]; |
86
|
|
|
$actual = $this->getDsm()->getSetters(); |
87
|
|
|
self::assertSame($expected, $actual); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @test |
92
|
|
|
*/ |
93
|
|
|
public function itCanGetReflection(): void |
94
|
|
|
{ |
95
|
|
|
$expected = new ReflectionClass(self::TEST_ENTITY_FQN); |
96
|
|
|
$actual = $this->getDsm()->getReflectionClass(); |
97
|
|
|
self::assertEquals($expected, $actual); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
*/ |
103
|
|
|
public function itCanGetShortName(): void |
104
|
|
|
{ |
105
|
|
|
$expected = 'Person'; |
106
|
|
|
$actual = $this->getDsm()->getShortName(); |
107
|
|
|
self::assertSame($expected, $actual); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @test |
112
|
|
|
*/ |
113
|
|
|
public function itCanGetPlural(): void |
114
|
|
|
{ |
115
|
|
|
$expected = 'people'; |
116
|
|
|
$actual = $this->getDsm()->getPlural(); |
117
|
|
|
self::assertSame($expected, $actual); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @test |
122
|
|
|
*/ |
123
|
|
|
public function itCanGetSingular(): void |
124
|
|
|
{ |
125
|
|
|
$expected = 'person'; |
126
|
|
|
$actual = $this->getDsm()->getSingular(); |
127
|
|
|
self::assertSame($expected, $actual); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @test |
132
|
|
|
*/ |
133
|
|
|
public function itCanGetStaticMethods(): void |
134
|
|
|
{ |
135
|
|
|
$expectedCount = 32; |
136
|
|
|
$actual = $this->getDsm()->getStaticMethods(); |
137
|
|
|
self::assertCount($expectedCount, $actual); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @test |
142
|
|
|
*/ |
143
|
|
|
public function itCanGetAndSetMetaData(): void |
144
|
|
|
{ |
145
|
|
|
$expected = new ClassMetadata(self::TEST_ENTITY_FQN); |
146
|
|
|
$actual = $this->getDsm()->setMetaData($expected)->getMetaData(); |
147
|
|
|
self::assertSame($expected, $actual); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @throws \ReflectionException |
152
|
|
|
* @test |
153
|
|
|
*/ |
154
|
|
|
public function itCanGetRequiredRelationProperties(): void |
155
|
|
|
{ |
156
|
|
|
$expected = [ |
157
|
|
|
'person' => [ |
158
|
|
|
'My\Test\Project\Entity\Interfaces\PersonInterface', |
159
|
|
|
], |
160
|
|
|
'orderAddresses' => [ |
161
|
|
|
'My\Test\Project\Entity\Interfaces\Order\AddressInterface[]', |
162
|
|
|
], |
163
|
|
|
]; |
164
|
|
|
$entityFqn = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ORDER; |
165
|
|
|
$actual = $this->getDsm($entityFqn) |
166
|
|
|
->getRequiredRelationProperties(); |
167
|
|
|
self::assertSame($expected, $actual); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @test |
172
|
|
|
*/ |
173
|
|
|
public function itCanGetEmbeddableProperties(): void |
174
|
|
|
{ |
175
|
|
|
$expected = [ |
176
|
|
|
'moneyEmbeddable' => MoneyEmbeddable::class, |
177
|
|
|
'addressEmbeddable' => AddressEmbeddable::class, |
178
|
|
|
'fullNameEmbeddable' => FullNameEmbeddable::class, |
179
|
|
|
]; |
180
|
|
|
$actual = $this->getDsm(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ALL_EMBEDDABLES) |
181
|
|
|
->getEmbeddableProperties(); |
182
|
|
|
self::assertSame($expected, $actual); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|