1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Util\Inflector; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractTest; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
10
|
|
|
|
11
|
|
|
class GenerateFieldCommandTest extends AbstractCommandTest |
12
|
|
|
{ |
13
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH.'/GenerateFieldCommandTest/'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
17
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
18
|
|
|
* @throws DoctrineStaticMetaException |
19
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
20
|
|
|
*/ |
21
|
|
|
public function testGenerateField() |
22
|
|
|
{ |
23
|
|
|
$command = $this->container->get(GenerateFieldCommand::class); |
24
|
|
|
$tester = $this->getCommandTester($command); |
25
|
|
|
$fieldsPath = self::WORK_DIR.'src/Entity/Fields'; |
26
|
|
|
$namespace = self::TEST_PROJECT_ROOT_NAMESPACE . AbstractGenerator::ENTITY_FIELD_TRAIT_NAMESPACE; |
27
|
|
|
|
28
|
|
|
$createdFiles = []; |
29
|
|
|
|
30
|
|
|
foreach (MappingHelper::COMMON_TYPES as $type) { |
31
|
|
|
$classy = Inflector::classify($type); |
32
|
|
|
$fieldFqn = $namespace . "\\$classy\\$classy"; |
33
|
|
|
$tester->execute( |
34
|
|
|
[ |
35
|
|
|
'-'.GenerateFieldCommand::OPT_PROJECT_ROOT_PATH_SHORT => self::WORK_DIR, |
36
|
|
|
'-'.GenerateFieldCommand::OPT_PROJECT_ROOT_NAMESPACE_SHORT => self::TEST_PROJECT_ROOT_NAMESPACE, |
37
|
|
|
'-'.GenerateFieldCommand::OPT_FQN_SHORT => $fieldFqn, |
38
|
|
|
'-'.GenerateFieldCommand::OPT_TYPE_SHORT => $type |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$createdFiles[] = "$fieldsPath/Interfaces/$classy/{$classy}FieldInterface.php"; |
43
|
|
|
$createdFiles[] = "$fieldsPath/Traits/$classy/{$classy}FieldTrait.php"; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
foreach ($createdFiles as $createdFile) { |
47
|
|
|
$this->assertNoMissedReplacements($createdFile); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->qaGeneratedCode(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|