1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\G\Entity\Testing\EntityGenerator; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator\FakerDataFillerFactory; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator\TestEntityGenerator; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator\TestEntityGeneratorFactory; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
12
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\GetGeneratedCodeContainerTrait; |
13
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
14
|
|
|
use Test\Code\Generator\Entities\Simple; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @large |
18
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator\TestEntityGenerator |
19
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
20
|
|
|
*/ |
21
|
|
|
class TestEntityGeneratorLargeTest extends AbstractLargeTest |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
use GetGeneratedCodeContainerTrait; |
25
|
|
|
|
26
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . |
27
|
|
|
self::TEST_TYPE_LARGE . |
28
|
|
|
'/TestEntityGeneratorLargeTest'; |
29
|
|
|
|
30
|
|
|
public const TEST_ENTITY_NAMESPACE_BASE = self::TEST_PROJECT_ROOT_NAMESPACE |
31
|
|
|
. '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME; |
32
|
|
|
|
33
|
|
|
private const TEST_ENTITY = self::TEST_ENTITY_NAMESPACE_BASE . TestCodeGenerator::TEST_ENTITY_PERSON; |
34
|
|
|
|
35
|
|
|
private const TEST_ENTITY_SIMPLE = self::TEST_ENTITY_NAMESPACE_BASE . TestCodeGenerator::TEST_ENTITY_SIMPLE; |
36
|
|
|
|
37
|
|
|
protected static $buildOnce = true; |
38
|
|
|
|
39
|
|
|
public function setup(): void |
40
|
|
|
{ |
41
|
|
|
parent::setUp(); |
42
|
|
|
if (false === self::$built) { |
43
|
|
|
$this->getTestCodeGenerator() |
44
|
|
|
->copyTo(self::WORK_DIR); |
45
|
|
|
} |
46
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
* @return EntityInterface |
52
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
53
|
|
|
* @throws \ErrorException |
54
|
|
|
* @throws \ReflectionException |
55
|
|
|
*/ |
56
|
|
|
public function itCanGenerateASingleEntity(): EntityInterface |
57
|
|
|
{ |
58
|
|
|
$entityFqn = self::TEST_ENTITY; |
59
|
|
|
$entityFqn = $this->getCopiedFqn($entityFqn); |
60
|
|
|
$testEntityGenerator = $this->getTestEntityGenerator($entityFqn); |
61
|
|
|
$entity = $testEntityGenerator->generateEntity(); |
62
|
|
|
$entityManager = $this->getEntityManager(); |
63
|
|
|
$entityManager->persist($entity); |
64
|
|
|
$entityManager->flush(); |
65
|
|
|
self::assertTrue(true); |
66
|
|
|
|
67
|
|
|
return $entity; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getTestEntityGenerator(string $entityFqn): TestEntityGenerator |
71
|
|
|
{ |
72
|
|
|
/** |
73
|
|
|
* @var TestEntityGeneratorFactory $factory |
74
|
|
|
*/ |
75
|
|
|
$factory = $this->container->get(TestEntityGeneratorFactory::class); |
76
|
|
|
$factory->setFakerDataProviderClasses( |
77
|
|
|
\constant( |
78
|
|
|
$this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . '\\AbstractEntityTest') . |
79
|
|
|
'::FAKER_DATA_PROVIDERS' |
80
|
|
|
) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return $factory->createForEntityFqn($entityFqn); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
88
|
|
|
* @throws \ErrorException |
89
|
|
|
* @throws \ReflectionException |
90
|
|
|
* @test |
91
|
|
|
*/ |
92
|
|
|
public function itCanGenerateTheAttributesEmailsEntity(): void |
93
|
|
|
{ |
94
|
|
|
$entityFqn = $this->getCopiedFqn( |
95
|
|
|
self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_EMAIL |
96
|
|
|
); |
97
|
|
|
$testEntityGenerator = $this->getTestEntityGenerator($entityFqn); |
98
|
|
|
$entity = $testEntityGenerator->generateEntity(); |
99
|
|
|
$entityManager = $this->getEntityManager(); |
100
|
|
|
$entityManager->persist($entity); |
101
|
|
|
$entityManager->flush(); |
102
|
|
|
self::assertTrue(true); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @test |
107
|
|
|
* |
108
|
|
|
* @throws \Doctrine\ORM\Mapping\MappingException |
109
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
110
|
|
|
* @throws \ErrorException |
111
|
|
|
* @throws \ReflectionException |
112
|
|
|
*/ |
113
|
|
|
public function itGeneratesEntitiesAndAssociatedEntities(): void |
114
|
|
|
{ |
115
|
|
|
$entities = []; |
116
|
|
|
$limit = ($this->isQuickTests() ? 2 : null); |
117
|
|
|
foreach (TestCodeGenerator::TEST_ENTITIES as $key => $entityFqn) { |
118
|
|
|
if ($limit !== null && $key === $limit) { |
119
|
|
|
break; |
120
|
|
|
} |
121
|
|
|
$entityFqn = $this->getCopiedFqn($entityFqn); |
122
|
|
|
$testEntityGenerator = $this->getTestEntityGenerator($entityFqn); |
123
|
|
|
$entity = $testEntityGenerator->generateEntity(); |
124
|
|
|
self::assertInstanceOf($entityFqn, $entity); |
125
|
|
|
$testEntityGenerator->addAssociationEntities($entity); |
126
|
|
|
$entities[] = $entity; |
127
|
|
|
} |
128
|
|
|
$this->getEntitySaver()->saveAll($entities); |
129
|
|
|
self::assertTrue(true); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @test |
135
|
|
|
* * @throws \Doctrine\ORM\Mapping\MappingException |
136
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
137
|
|
|
* @throws \ReflectionException |
138
|
|
|
*/ |
139
|
|
|
public function itCanGenerateMultipleEntities(): void |
140
|
|
|
{ |
141
|
|
|
$entityFqn = $this->getCopiedFqn(self::TEST_ENTITY); |
142
|
|
|
$count = $this->isQuickTests() ? 2 : 100; |
143
|
|
|
$actual = $this->getTestEntityGenerator($entityFqn)->generateEntities($count); |
144
|
|
|
self::assertCount($count, $actual); |
145
|
|
|
self::assertInstanceOf($entityFqn, current($actual)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @test |
150
|
|
|
* * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
151
|
|
|
* @throws \ReflectionException |
152
|
|
|
*/ |
153
|
|
|
public function itCanCreateAnEmptyEntityUsingTheFactory(): void |
154
|
|
|
{ |
155
|
|
|
$entityFqn = $this->getCopiedFqn(self::TEST_ENTITY_SIMPLE); |
156
|
|
|
$entity = $this->getTestEntityGenerator($entityFqn)->create(); |
157
|
|
|
self::assertInstanceOf($entityFqn, $entity); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @test |
162
|
|
|
* * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
163
|
|
|
* @throws \ReflectionException |
164
|
|
|
*/ |
165
|
|
|
public function itCanCreateAnEntityWithValuesSet(): void |
166
|
|
|
{ |
167
|
|
|
$entityFqn = $this->getCopiedFqn(self::TEST_ENTITY_SIMPLE); |
168
|
|
|
$values = [ |
169
|
|
|
'string' => 'this has been set', |
170
|
|
|
]; |
171
|
|
|
$entity = $this->getTestEntityGenerator($entityFqn)->create($values); |
172
|
|
|
self::assertSame($values['string'], $entity->getString()); |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @test |
177
|
|
|
* @throws \Doctrine\ORM\Mapping\MappingException |
178
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
179
|
|
|
* @throws \ReflectionException |
180
|
|
|
*/ |
181
|
|
|
public function itCanYieldUnsavedEntities(): void |
182
|
|
|
{ |
183
|
|
|
$entityFqn = $this->getCopiedFqn(self::TEST_ENTITY); |
184
|
|
|
$testEntityGenerator = $this->getTestEntityGenerator($entityFqn); |
185
|
|
|
$generator = $testEntityGenerator->getGenerator(3); |
186
|
|
|
$entity1 = null; |
187
|
|
|
foreach ($generator as $entity) { |
188
|
|
|
$entity1 = $entity; |
189
|
|
|
break; |
190
|
|
|
} |
191
|
|
|
$generator->next(); |
192
|
|
|
$entity3 = $generator->current(); |
193
|
|
|
$generator->next(); |
194
|
|
|
$entity2 = $generator->current(); |
195
|
|
|
|
196
|
|
|
self::assertInstanceOf($entityFqn, $entity1); |
197
|
|
|
self::assertInstanceOf($entityFqn, $entity2); |
198
|
|
|
self::assertInstanceOf($entityFqn, $entity3); |
199
|
|
|
self::assertNotSame($entity1, $entity2); |
200
|
|
|
self::assertNotSame($entity1, $entity3); |
201
|
|
|
self::assertNotSame($entity2, $entity3); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @test |
206
|
|
|
*/ |
207
|
|
|
public function itWillUseACustomDataFiller(): void |
208
|
|
|
{ |
209
|
|
|
/** @var FakerDataFillerFactory $factory */ |
210
|
|
|
$factory = $this->container->get(FakerDataFillerFactory::class); |
211
|
|
|
$entityFqn = trim($this->getCopiedFqn(self::TEST_ENTITY_SIMPLE), '\\'); |
212
|
|
|
$fakerDataFiller = $this->getCopiedFqn( |
213
|
|
|
self::TEST_PROJECT_ROOT_NAMESPACE . '\\Assets\\Entity\\FakerDataFillers\\SimpleFakerDataFiller' |
214
|
|
|
); |
215
|
|
|
$factory->setCustomFakerDataFillersFqns([$entityFqn => $fakerDataFiller]); |
216
|
|
|
$testEntityGenerator = $this->getTestEntityGenerator($entityFqn); |
217
|
|
|
$generator = $testEntityGenerator->getGenerator(3); |
218
|
|
|
foreach ($generator as $entity) { |
219
|
|
|
/** @var Simple $entity */ |
220
|
|
|
$entityString = $entity->getString(); |
221
|
|
|
self::assertSame('Set from a custom Faker Data Filler', $entityString); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths