|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Inflector\Inflector; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetFieldCommand; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class SetFieldCommandTest |
|
13
|
|
|
* |
|
14
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command |
|
15
|
|
|
* @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\SetFieldCommand |
|
16
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
17
|
|
|
*/ |
|
18
|
|
|
class SetFieldCommandTest extends AbstractCommandTest |
|
19
|
|
|
{ |
|
20
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/SetFieldCommandTest/'; |
|
21
|
|
|
|
|
22
|
|
|
private const FIELDS_TO_TYPES = [ |
|
23
|
|
|
MappingHelper::TYPE_STRING, |
|
24
|
|
|
MappingHelper::TYPE_FLOAT, |
|
25
|
|
|
MappingHelper::TYPE_INTEGER, |
|
26
|
|
|
MappingHelper::TYPE_TEXT, |
|
27
|
|
|
MappingHelper::TYPE_DATETIME, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @test |
|
32
|
|
|
* @large |
|
33
|
|
|
* @covers ::execute |
|
34
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
35
|
|
|
* @throws \ReflectionException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function setField(): void |
|
38
|
|
|
{ |
|
39
|
|
|
list($entityFqn) = $this->generateEntities(); |
|
40
|
|
|
|
|
41
|
|
|
$command = $this->container->get(SetFieldCommand::class); |
|
42
|
|
|
$tester = $this->getCommandTester($command); |
|
43
|
|
|
foreach ($this->generateFields() as $fieldFqn) { |
|
44
|
|
|
$tester->execute( |
|
45
|
|
|
[ |
|
46
|
|
|
'-' . SetFieldCommand::OPT_FIELD_SHORT => $fieldFqn, |
|
47
|
|
|
'-' . SetFieldCommand::OPT_ENTITY_SHORT => $entityFqn, |
|
48
|
|
|
] |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
self::assertNotFalse( |
|
52
|
|
|
\strpos( |
|
53
|
|
|
file_get_contents(static::WORK_DIR . '/src/Entities/' . $this->getName() . '/FirstEntity.php'), |
|
54
|
|
|
'use DatetimeFieldTrait' |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
self::assertTrue($this->qaGeneratedCode()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return array |
|
62
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
63
|
|
|
* @throws \ReflectionException |
|
64
|
|
|
*/ |
|
65
|
|
|
private function generateFields(): array |
|
66
|
|
|
{ |
|
67
|
|
|
$fieldGenerator = $this->getFieldGenerator(); |
|
68
|
|
|
$return = []; |
|
69
|
|
|
$namespace = static::TEST_PROJECT_ROOT_NAMESPACE . AbstractGenerator::ENTITY_FIELD_TRAIT_NAMESPACE; |
|
70
|
|
|
|
|
71
|
|
|
foreach (self::FIELDS_TO_TYPES as $type) { |
|
72
|
|
|
$classy = Inflector::classify($type); |
|
73
|
|
|
$fieldFqn = "$namespace\\$classy\\$classy"; |
|
74
|
|
|
$return[] = $fieldGenerator->generateField($fieldFqn, $type); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $return; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|