1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\CodeGeneration; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Geo\AddressEmbeddableInterface; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Identity\FullNameEmbeddableInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo\AddressEmbeddable; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity\FullNameEmbeddable; |
12
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use ts\Reflection\ReflectionClass; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper |
19
|
|
|
* @small |
20
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
21
|
|
|
*/ |
22
|
|
|
class NamespaceHelperTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var NamespaceHelper |
26
|
|
|
*/ |
27
|
|
|
private static $helper; |
28
|
|
|
|
29
|
|
|
public static function setUpBeforeClass() |
30
|
|
|
{ |
31
|
|
|
self::$helper = new NamespaceHelper(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function itCanGetAllTheArchetypeFieldFqns(): void |
38
|
|
|
{ |
39
|
|
|
$actual = self::$helper->getAllArchetypeFieldFqns(); |
40
|
|
|
foreach ($actual as $fqn) { |
41
|
|
|
$reflection = new ReflectionClass($fqn); |
42
|
|
|
self::assertTrue($reflection->isTrait()); |
43
|
|
|
} |
44
|
|
|
self::assertGreaterThan(10, count($actual)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @test |
49
|
|
|
*/ |
50
|
|
|
public function itCanGetTheEmbeddableObjectFqnFromTheInterfaceFqn(): void |
51
|
|
|
{ |
52
|
|
|
$expectedToInterface = [ |
53
|
|
|
MoneyEmbeddable::class => MoneyEmbeddableInterface::class, |
54
|
|
|
AddressEmbeddable::class => AddressEmbeddableInterface::class, |
55
|
|
|
FullNameEmbeddable::class => FullNameEmbeddableInterface::class, |
56
|
|
|
]; |
57
|
|
|
foreach ($expectedToInterface as $expected => $interface) { |
58
|
|
|
$this->assertSame( |
59
|
|
|
$expected, |
60
|
|
|
self::$helper->getEmbeddableObjectFqnFromEmbeddableObjectInterfaceFqn($interface) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
|
public function itCanGetTheEntityFqnFromTheEntityInterfaceFqn(): void |
69
|
|
|
{ |
70
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Foo\\BlahEntity'; |
71
|
|
|
$actual = self::$helper->getEntityFqnFromEntityInterfaceFqn( |
72
|
|
|
AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Interfaces\\Foo\\BlahEntityInterface' |
73
|
|
|
); |
74
|
|
|
self::assertSame($expected, $actual); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @test |
79
|
|
|
*/ |
80
|
|
|
public function itCanGetTheEntityFactoryFqnFromEntityFqn(): void |
81
|
|
|
{ |
82
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Factories\\Blah\\FooFactory'; |
83
|
|
|
$actual = self::$helper->getFactoryFqnFromEntityFqn( |
84
|
|
|
AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Blah\\Foo' |
85
|
|
|
); |
86
|
|
|
self::assertSame($expected, $actual); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @test |
91
|
|
|
*/ |
92
|
|
|
public function itCanGetTheEntityFqnFromEntityFactoryFqn(): void |
93
|
|
|
{ |
94
|
|
|
$factory = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Factories\\Blah\\FooFactory'; |
95
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Blah\\Foo'; |
96
|
|
|
$actual = self::$helper->getEntityFqnFromEntityFactoryFqn($factory); |
97
|
|
|
self::assertSame($expected, $actual); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
*/ |
103
|
|
|
public function itCanGetTheEntityDtoFactoryFqnFromEntityFqn(): void |
104
|
|
|
{ |
105
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Factories\\Blah\\FooDtoFactory'; |
106
|
|
|
$actual = self::$helper->getDtoFactoryFqnFromEntityFqn( |
107
|
|
|
AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Blah\\Foo' |
108
|
|
|
); |
109
|
|
|
self::assertSame($expected, $actual); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @test |
114
|
|
|
*/ |
115
|
|
|
public function itCanGetTheEntityFqnFromEntityDtoFactoryFqn(): void |
116
|
|
|
{ |
117
|
|
|
$factory = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Factories\\Blah\\FooDtoFactory'; |
118
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Blah\\Foo'; |
119
|
|
|
$actual = self::$helper->getEntityFqnFromEntityDtoFactoryFqn($factory); |
120
|
|
|
self::assertSame($expected, $actual); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @test |
125
|
|
|
* @large |
126
|
|
|
*/ |
127
|
|
|
public function getFixtureFqnFromEntityFqn(): void |
128
|
|
|
{ |
129
|
|
|
$expected = AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Assets\\Entity\\Fixtures\\Blah\\FooFixture'; |
130
|
|
|
$actual = self::$helper->getFixtureFqnFromEntityFqn( |
131
|
|
|
AbstractTest::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\Blah\\Foo' |
132
|
|
|
); |
133
|
|
|
self::assertSame($expected, $actual); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @test |
138
|
|
|
*/ |
139
|
|
|
public function cropSuffix(): void |
140
|
|
|
{ |
141
|
|
|
$fqn = 'FooBar'; |
142
|
|
|
$suffix = 'Bar'; |
143
|
|
|
$expected = 'Foo'; |
144
|
|
|
$actual = self::$helper->cropSuffix($fqn, $suffix); |
145
|
|
|
self::assertSame($expected, $actual); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @test |
150
|
|
|
* @large |
151
|
|
|
* */ |
152
|
|
|
public function swapSuffix(): void |
153
|
|
|
{ |
154
|
|
|
$fqn = 'FooBar'; |
155
|
|
|
$currentSuffix = 'Bar'; |
156
|
|
|
$newSuffix = 'Baz'; |
157
|
|
|
$expected = 'FooBaz'; |
158
|
|
|
$actual = self::$helper->swapSuffix($fqn, $currentSuffix, $newSuffix); |
159
|
|
|
self::assertSame($expected, $actual); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @test |
164
|
|
|
* @large |
165
|
|
|
* */ |
166
|
|
|
public function cropSuffixWhereSuffixNotInThere(): void |
167
|
|
|
{ |
168
|
|
|
$fqn = 'FooBar'; |
169
|
|
|
$suffix = 'Cheese'; |
170
|
|
|
$expected = 'FooBar'; |
171
|
|
|
$actual = self::$helper->cropSuffix($fqn, $suffix); |
172
|
|
|
self::assertSame($expected, $actual); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @test |
177
|
|
|
*/ |
178
|
|
|
public function tidy(): void |
179
|
|
|
{ |
180
|
|
|
$namespaceToExpected = [ |
181
|
|
|
'Test\\\\Multiple\\\\\\\Separators' => 'Test\\Multiple\\Separators', |
182
|
|
|
'No\\Changes\\Required' => 'No\\Changes\\Required', |
183
|
|
|
]; |
184
|
|
|
foreach ($namespaceToExpected as $namespace => $expected) { |
185
|
|
|
self::assertSame($expected, self::$helper->tidy($namespace)); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @test |
191
|
|
|
*/ |
192
|
|
|
public function root(): void |
193
|
|
|
{ |
194
|
|
|
$namespaceToExpected = [ |
195
|
|
|
'\\Test\\\\Multiple\\\\\\\Separators' => 'Test\\Multiple\\Separators', |
196
|
|
|
'No\\Changes\\Required' => 'No\\Changes\\Required', |
197
|
|
|
]; |
198
|
|
|
foreach ($namespaceToExpected as $namespace => $expected) { |
199
|
|
|
self::assertSame($expected, self::$helper->root($namespace)); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @test |
205
|
|
|
*/ |
206
|
|
|
public function itCanGetADtoFqnFromAnEntityFqn(): void |
207
|
|
|
{ |
208
|
|
|
$expected = '\\Test\\Project\\Entity\\DataTransferObjects\\Foo\\BarDto'; |
209
|
|
|
$actual = self::$helper->getEntityDtoFqnFromEntityFqn( |
210
|
|
|
'\\Test\\Project\\Entities\\Foo\\Bar' |
211
|
|
|
); |
212
|
|
|
self::assertSame($expected, $actual); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @test |
217
|
|
|
*/ |
218
|
|
|
public function itCanGetAnUpsertFqnFromAnEntityFqn(): void |
219
|
|
|
{ |
220
|
|
|
$expected = '\\Test\\Project\\Entity\\Savers\\Foo\\BarUpserter'; |
221
|
|
|
$actual = self::$helper->getEntityUpserterFqnFromEntityFqn( |
222
|
|
|
'\\Test\\Project\\Entities\\Foo\\Bar' |
223
|
|
|
); |
224
|
|
|
self::assertSame($expected, $actual); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @test |
229
|
|
|
*/ |
230
|
|
|
public function itCanGetAnEntityFqnFromAnUpsertFqn(): void |
231
|
|
|
{ |
232
|
|
|
$expected = '\\Test\\Project\\Entities\\Foo\\Bar'; |
233
|
|
|
$actual = self::$helper->getEntityFqnFromEntityUpserterFqn( |
234
|
|
|
'\\Test\\Project\\Entity\\Savers\\Foo\\BarUpserter' |
235
|
|
|
); |
236
|
|
|
self::assertSame($expected, $actual); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @test |
241
|
|
|
*/ |
242
|
|
|
public function itCanGetAnUnitOfWorkHelperFqnFromAnEntityFqn(): void |
243
|
|
|
{ |
244
|
|
|
$expected = '\\Test\\Project\\Entity\\Savers\\Foo\\BarUnitOfWorkHelper'; |
245
|
|
|
$actual = self::$helper->getEntityUnitOfWorkHelperFqnFromEntityFqn( |
246
|
|
|
'\\Test\\Project\\Entities\\Foo\\Bar' |
247
|
|
|
); |
248
|
|
|
self::assertSame($expected, $actual); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @test |
253
|
|
|
*/ |
254
|
|
|
public function itCanGetAnEntityFqnFromAnUnitOfWorkHelperFqn(): void |
255
|
|
|
{ |
256
|
|
|
$expected = '\\Test\\Project\\Entities\\Foo\\Bar'; |
257
|
|
|
$actual = self::$helper->getEntityFqnFromEntityUnitOfWorkHelperFqn( |
258
|
|
|
'\\Test\\Project\\Entity\\Savers\\Foo\\BarUnitOfWorkHelper' |
259
|
|
|
); |
260
|
|
|
self::assertSame($expected, $actual); |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|