|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\EntityGenerator; |
|
10
|
|
|
use Symfony\Component\Console\Application; |
|
11
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
12
|
|
|
|
|
13
|
|
|
abstract class AbstractCommandIntegrationTest extends AbstractIntegrationTest |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param AbstractCommand $command |
|
18
|
|
|
* |
|
19
|
|
|
* @return CommandTester |
|
20
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
21
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function getCommandTester(AbstractCommand $command): CommandTester |
|
24
|
|
|
{ |
|
25
|
|
|
$application = new Application(); |
|
26
|
|
|
//$_SERVER[ConfigInterface::PARAM_ENTITIES_PATH] = static::WORK_DIR.'/src/Entities'; |
|
27
|
|
|
$helperSet = ConsoleRunner::createHelperSet( |
|
28
|
|
|
$this->container->get(EntityManager::class) |
|
29
|
|
|
); |
|
30
|
|
|
$application->setHelperSet($helperSet); |
|
31
|
|
|
$application->add($command); |
|
32
|
|
|
|
|
33
|
|
|
return new CommandTester($command); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function getEntityPath(string $entityFqn) |
|
37
|
|
|
{ |
|
38
|
|
|
$entityPath = str_replace( |
|
39
|
|
|
'\\', |
|
40
|
|
|
'/', |
|
41
|
|
|
\substr( |
|
42
|
|
|
$entityFqn, |
|
43
|
|
|
\strpos( |
|
44
|
|
|
$entityFqn, |
|
45
|
|
|
'Entities\\' |
|
46
|
|
|
) + \strlen('Entities\\') |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
return '/'.$entityPath; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array |
|
55
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function generateEntities(): array |
|
58
|
|
|
{ |
|
59
|
|
|
$entityGenerator = $this->container->get(EntityGenerator::class); |
|
60
|
|
|
$entityGenerator->setProjectRootNamespace(static::TEST_PROJECT_ROOT_NAMESPACE) |
|
61
|
|
|
->setPathToProjectRoot(static::WORK_DIR); |
|
62
|
|
|
$baseNamespace = self::TEST_PROJECT_ROOT_NAMESPACE.'\\' |
|
63
|
|
|
.AbstractGenerator::ENTITIES_FOLDER_NAME.'\\'.$this->getName(); |
|
64
|
|
|
$entityFqns = [ |
|
65
|
|
|
$baseNamespace.'\\FirstEntity', |
|
66
|
|
|
$baseNamespace.'\\Second\\SecondEntity', |
|
67
|
|
|
$baseNamespace.'\\Now\\Third\\ThirdEntity', |
|
68
|
|
|
]; |
|
69
|
|
|
foreach ($entityFqns as $fullyQualifiedName) { |
|
70
|
|
|
$entityGenerator->generateEntity($fullyQualifiedName); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $entityFqns; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|