|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractTest; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\AbstractCommand; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
|
8
|
|
|
|
|
9
|
|
|
class EntityGeneratorTest extends AbstractTest |
|
10
|
|
|
{ |
|
11
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH.'/EntityGeneratorTest/'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testGenerateEntity() |
|
16
|
|
|
{ |
|
17
|
|
|
$fqn = static::TEST_PROJECT_ROOT_NAMESPACE |
|
18
|
|
|
.'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
19
|
|
|
.'\\Yet\\Another\\TestEntity'; |
|
20
|
|
|
$this->getEntityGenerator()->generateEntity($fqn); |
|
21
|
|
|
$createdFile = static::WORK_DIR |
|
22
|
|
|
.'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER |
|
23
|
|
|
.'/'.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
24
|
|
|
.'/Yet/Another/TestEntity.php'; |
|
25
|
|
|
$this->assertNoMissedReplacements($createdFile); |
|
26
|
|
|
|
|
27
|
|
|
$createdFile = static::WORK_DIR |
|
28
|
|
|
.'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER |
|
29
|
|
|
.'/'.AbstractGenerator::ENTITY_REPOSITORIES_FOLDER_NAME |
|
30
|
|
|
.'/Yet/Another/TestEntityRepository.php'; |
|
31
|
|
|
$this->assertNoMissedReplacements($createdFile); |
|
32
|
|
|
$this->qaGeneratedCode(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGenerateRepository(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$entityFqn = static::TEST_PROJECT_ROOT_NAMESPACE |
|
38
|
|
|
.'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
39
|
|
|
.'\\Some\\Other\\TestEntity'; |
|
40
|
|
|
|
|
41
|
|
|
$repositoryFqn = '\\'.static::TEST_PROJECT_ROOT_NAMESPACE |
|
42
|
|
|
.AbstractGenerator::ENTITY_REPOSITORIES_NAMESPACE |
|
43
|
|
|
.'\\Some\\Other\\TestEntityRepository'; |
|
44
|
|
|
|
|
45
|
|
|
$this->getEntityGenerator()->generateEntity($entityFqn); |
|
46
|
|
|
$this->setupCopiedWorkDir(); |
|
47
|
|
|
|
|
48
|
|
|
$entityManager = $this->getEntityManager(); |
|
49
|
|
|
$repository = $entityManager->getRepository($this->getCopiedFqn($entityFqn)); |
|
50
|
|
|
$this->assertInstanceOf($this->getCopiedFqn($repositoryFqn), $repository); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function testGenerateEntityWithDeepNesting() |
|
55
|
|
|
{ |
|
56
|
|
|
$entityNamespace = static::TEST_PROJECT_ROOT_NAMESPACE.'\\' |
|
57
|
|
|
.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
58
|
|
|
.'\\Human\\Head\\Eye'; |
|
59
|
|
|
$entityFullyQualifiedName = $entityNamespace.'\\Lash'; |
|
60
|
|
|
$this->getEntityGenerator() |
|
61
|
|
|
->setProjectRootNamespace(static::TEST_PROJECT_ROOT_NAMESPACE) |
|
62
|
|
|
->generateEntity($entityFullyQualifiedName); |
|
63
|
|
|
|
|
64
|
|
|
$createdFile = static::WORK_DIR |
|
65
|
|
|
.'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER |
|
66
|
|
|
.'/'.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
67
|
|
|
.'/Human/Head/Eye/Lash.php'; |
|
68
|
|
|
$this->assertNoMissedReplacements($createdFile); |
|
69
|
|
|
$this->assertContains("namespace $entityNamespace;", file_get_contents($createdFile)); |
|
70
|
|
|
|
|
71
|
|
|
$createdFile = static::WORK_DIR |
|
72
|
|
|
.'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER |
|
73
|
|
|
.'/'.AbstractGenerator::ENTITY_REPOSITORIES_FOLDER_NAME |
|
74
|
|
|
.'/Human/Head/Eye/LashRepository.php'; |
|
75
|
|
|
$this->assertNoMissedReplacements($createdFile); |
|
76
|
|
|
$entityFullyQualifiedName = $this->container->get(NamespaceHelper::class)->tidy( |
|
77
|
|
|
static::TEST_PROJECT_ROOT_NAMESPACE.'\\' |
|
78
|
|
|
.AbstractGenerator::ENTITY_REPOSITORIES_NAMESPACE |
|
79
|
|
|
.'\\Human\\Head\\Eye' |
|
80
|
|
|
); |
|
81
|
|
|
$this->assertContains("namespace $entityFullyQualifiedName;", file_get_contents($createdFile)); |
|
82
|
|
|
|
|
83
|
|
|
$this->qaGeneratedCode(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|