|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEntityCommand; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class GenerateEntityCommandTest |
|
12
|
|
|
* |
|
13
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command |
|
14
|
|
|
* @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\GenerateEntityCommand |
|
15
|
|
|
*/ |
|
16
|
|
|
class GenerateEntityCommandTest extends AbstractCommandTest |
|
17
|
|
|
{ |
|
18
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/GenerateEntityCommandTest/'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @test |
|
22
|
|
|
* @large |
|
23
|
|
|
* @covers ::execute |
|
24
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
|
25
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
|
26
|
|
|
* @throws DoctrineStaticMetaException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function generateEntity(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$command = $this->container->get(GenerateEntityCommand::class); |
|
31
|
|
|
$tester = $this->getCommandTester($command); |
|
32
|
|
|
$tester->execute( |
|
33
|
|
|
[ |
|
34
|
|
|
'-' . GenerateEntityCommand::OPT_PROJECT_ROOT_PATH_SHORT => self::WORK_DIR, |
|
35
|
|
|
'-' . GenerateEntityCommand::OPT_PROJECT_ROOT_NAMESPACE_SHORT => self::TEST_PROJECT_ROOT_NAMESPACE, |
|
36
|
|
|
'-' . GenerateEntityCommand::OPT_FQN_SHORT => self::TEST_PROJECT_ROOT_NAMESPACE . |
|
37
|
|
|
'\\' |
|
38
|
|
|
. |
|
39
|
|
|
AbstractGenerator::ENTITIES_FOLDER_NAME |
|
40
|
|
|
. |
|
41
|
|
|
'\\This\\Is\\A\\TestEntity', |
|
42
|
|
|
] |
|
43
|
|
|
); |
|
44
|
|
|
$createdFiles = [ |
|
45
|
|
|
$this->entitiesPath . '/This/Is/A/TestEntity.php', |
|
46
|
|
|
$this->entitiesPath . '/../../tests/Entities/This/Is/A/TestEntityTest.php', |
|
47
|
|
|
]; |
|
48
|
|
|
foreach ($createdFiles as $createdFile) { |
|
49
|
|
|
$this->assertNoMissedReplacements($createdFile); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @test |
|
55
|
|
|
* @large |
|
56
|
|
|
* @covers ::execute |
|
57
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
|
58
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
|
59
|
|
|
* @throws DoctrineStaticMetaException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function generateEntityWithoutUuid(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$command = $this->container->get(GenerateEntityCommand::class); |
|
64
|
|
|
$tester = $this->getCommandTester($command); |
|
65
|
|
|
$tester->execute( |
|
66
|
|
|
[ |
|
67
|
|
|
'-' . GenerateEntityCommand::OPT_PROJECT_ROOT_PATH_SHORT => self::WORK_DIR, |
|
68
|
|
|
'-' . GenerateEntityCommand::OPT_PROJECT_ROOT_NAMESPACE_SHORT => self::TEST_PROJECT_ROOT_NAMESPACE, |
|
69
|
|
|
'-' . GenerateEntityCommand::OPT_FQN_SHORT => self::TEST_PROJECT_ROOT_NAMESPACE |
|
70
|
|
|
. |
|
71
|
|
|
'\\' |
|
72
|
|
|
. |
|
73
|
|
|
AbstractGenerator::ENTITIES_FOLDER_NAME |
|
74
|
|
|
. |
|
75
|
|
|
'\\This\\Is\\Another\\TestEntity', |
|
76
|
|
|
'-' . GenerateEntityCommand::OPT_INT_PRIMARY_KEY_SHORT => true, |
|
77
|
|
|
] |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$entityPath = $this->entitiesPath . '/This/Is/Another/TestEntity.php'; |
|
81
|
|
|
|
|
82
|
|
|
$this->assertNoMissedReplacements($entityPath); |
|
83
|
|
|
$this->assertFileContains($entityPath, 'IntegerIdFieldTrait'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|