|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Builder\Builder; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\EnumFieldTrait; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Builder\Builder |
|
12
|
|
|
*/ |
|
13
|
|
|
class BuilderTest extends AbstractTest |
|
14
|
|
|
{ |
|
15
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/BuilderTest/'; |
|
16
|
|
|
|
|
17
|
|
|
protected const TEST_ENTITY_FQN_BASE = self::TEST_PROJECT_ROOT_NAMESPACE |
|
18
|
|
|
. '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME |
|
19
|
|
|
. '\\BuilderTestEntity'; |
|
20
|
|
|
|
|
21
|
|
|
protected const TEST_ENTITY_ONE = self::TEST_ENTITY_FQN_BASE . '\\EntityOne'; |
|
22
|
|
|
protected const TEST_ENTITY_TWO = self::TEST_ENTITY_FQN_BASE . '\\EntityTwo'; |
|
23
|
|
|
protected const TEST_ENTITIES = [ |
|
24
|
|
|
self::TEST_ENTITY_ONE, |
|
25
|
|
|
self::TEST_ENTITY_TWO, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
protected const TEST_FIELD_FQN_BASE = self::TEST_PROJECT_ROOT_NAMESPACE |
|
29
|
|
|
. '\\Entity\\Fields\\Traits'; |
|
30
|
|
|
|
|
31
|
|
|
protected const TEST_FIELD_ENITY_ONE_ENUM = self::TEST_FIELD_FQN_BASE . '\\EntityOne\\EnumFieldTrait'; |
|
32
|
|
|
|
|
33
|
|
|
protected const TEST_FIELDS_ENTITY_ONE = [ |
|
34
|
|
|
self::TEST_FIELD_ENITY_ONE_ENUM => EnumFieldTrait::class, |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
protected static $buildOnce = true; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var Builder |
|
40
|
|
|
*/ |
|
41
|
|
|
private $builder; |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() |
|
44
|
|
|
{ |
|
45
|
|
|
parent::setup(); |
|
46
|
|
|
if (true !== self::$built) { |
|
47
|
|
|
foreach (self::TEST_ENTITIES as $entityFqn) { |
|
48
|
|
|
$this->getEntityGenerator()->generateEntity($entityFqn); |
|
49
|
|
|
} |
|
50
|
|
|
foreach (self::TEST_FIELDS_ENTITY_ONE as $fieldFqn => $fieldType) { |
|
51
|
|
|
$this->getFieldGenerator()->generateField($fieldFqn, $fieldType); |
|
52
|
|
|
$this->getFieldSetter()->setEntityHasField(self::TEST_ENTITY_ONE, $fieldFqn); |
|
53
|
|
|
} |
|
54
|
|
|
self::$built = true; |
|
55
|
|
|
} |
|
56
|
|
|
$this->setupCopiedWorkDir(); |
|
57
|
|
|
$this->builder = new Builder( |
|
58
|
|
|
$this->getEntityGenerator(), |
|
59
|
|
|
$this->getFieldGenerator(), |
|
60
|
|
|
$this->getFieldSetter(), |
|
61
|
|
|
$this->getRelationsGenerator(), |
|
62
|
|
|
$this->getArchetypeEmbeddableGenerator(), |
|
63
|
|
|
$this->getEntityEmbeddableSetter(), |
|
64
|
|
|
$this->getCodeHelper(), |
|
65
|
|
|
$this->getUnusedRelationsRemover() |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @test |
|
71
|
|
|
* @large |
|
72
|
|
|
*/ |
|
73
|
|
|
public function itCanUpdateEnumValueOptions(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$options = [ |
|
76
|
|
|
'this', |
|
77
|
|
|
'that', |
|
78
|
|
|
]; |
|
79
|
|
|
$this->builder->setEnumOptionsOnInterface( |
|
80
|
|
|
'\BuilderTest_itCanUpdateEnumValueOptions_\Entity\Fields\Interfaces\EntityOne\EnumFieldInterface', |
|
81
|
|
|
$options |
|
82
|
|
|
); |
|
83
|
|
|
$code = file_get_contents( |
|
84
|
|
|
$this->copiedWorkDir . '/src/Entity/Fields/Interfaces/EntityOne/EnumFieldInterface.php' |
|
85
|
|
|
); |
|
86
|
|
|
self::assertNotContains('FOO', $code); |
|
87
|
|
|
self::assertNotContains('BAR', $code); |
|
88
|
|
|
self::assertNotRegExp('%^\s+const%', $code); |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|