|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Savers; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractFunctionalTest; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator; |
|
9
|
|
|
|
|
10
|
|
|
class AbstractEntitySpecificSaverTest extends AbstractFunctionalTest |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/AbstractEntitySpecificSaverTest'; |
|
14
|
|
|
|
|
15
|
|
|
private const TEST_ENTITTES = [ |
|
16
|
|
|
self::TEST_PROJECT_ROOT_NAMESPACE.'\\Entities\\TestOne', |
|
17
|
|
|
self::TEST_PROJECT_ROOT_NAMESPACE.'\\Entities\\Deeply\\Nested\\TestTwo', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
private $built = false; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var EntitySaverFactory |
|
23
|
|
|
*/ |
|
24
|
|
|
private $saverFactory; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private $generatedEntities; |
|
29
|
|
|
|
|
30
|
|
|
public function setup() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::setup(); |
|
33
|
|
|
if (true !== $this->built) { |
|
34
|
|
|
foreach (self::TEST_ENTITTES as $entityFqn) { |
|
35
|
|
|
$this->getEntityGenerator()->generateEntity($entityFqn, true); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
$this->setupCopiedWorkDirAndCreateDatabase(); |
|
39
|
|
|
$this->saverFactory = new EntitySaverFactory( |
|
40
|
|
|
$this->getEntityManager(), |
|
41
|
|
|
new EntitySaver($this->getEntityManager()), |
|
42
|
|
|
New NamespaceHelper() |
|
43
|
|
|
); |
|
44
|
|
|
foreach (self::TEST_ENTITTES as $entityFqn) { |
|
45
|
|
|
$entityFqn = $this->getCopiedFqn($entityFqn); |
|
46
|
|
|
$this->generatedEntities[$entityFqn] = (new TestEntityGenerator( |
|
47
|
|
|
100.0, |
|
48
|
|
|
[], |
|
49
|
|
|
new \ReflectionClass($entityFqn), |
|
50
|
|
|
$this->saverFactory |
|
51
|
|
|
))->generateEntities($this->getEntityManager(), $entityFqn, 10); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getEntitySpecificSaver(string $entityFqn): AbstractEntitySpecificSaver |
|
56
|
|
|
{ |
|
57
|
|
|
$saver = $this->saverFactory->getSaverForEntityFqn($entityFqn); |
|
58
|
|
|
if ($saver instanceof AbstractEntitySpecificSaver) { |
|
59
|
|
|
return $saver; |
|
60
|
|
|
} |
|
61
|
|
|
$this->fail( |
|
62
|
|
|
'$saver for $entityFqn '.$entityFqn.' is not an instance of AbstractEntitySpecificSaver' |
|
63
|
|
|
); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testRemoveAll() |
|
67
|
|
|
{ |
|
68
|
|
|
foreach (self::TEST_ENTITTES as $entityFqn) { |
|
69
|
|
|
$entityFqn = $this->getCopiedFqn($entityFqn); |
|
70
|
|
|
$saver = $this->getEntitySpecificSaver($entityFqn); |
|
71
|
|
|
$loaded = $this->getEntityManager()->getRepository($entityFqn)->findAll(); |
|
72
|
|
|
$this->assertSame($this->generatedEntities[$entityFqn], $loaded); |
|
73
|
|
|
$saver->removeAll($loaded); |
|
74
|
|
|
$reLoaded = $this->getEntityManager()->getRepository($entityFqn)->findAll(); |
|
75
|
|
|
$this->assertSame([], $reLoaded); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testRemove() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->markTestIncomplete('TODO'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testSaveAll() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->markTestIncomplete('TODO'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testSave() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->markTestIncomplete('TODO'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: