|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Zenify\DoctrineMigrations\Tests\DI\MigrationsExtension; |
|
6
|
|
|
|
|
7
|
|
|
use Arachne\EventDispatcher\DI\EventDispatcherExtension; |
|
8
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand; |
|
9
|
|
|
use Nette\DI\Compiler; |
|
10
|
|
|
use Nette\DI\ContainerBuilder; |
|
11
|
|
|
use Nette\DI\ServiceDefinition; |
|
12
|
|
|
use Nette\DI\Statement; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Symfony\Component\Console\Application; |
|
15
|
|
|
use Zenify\DoctrineMigrations\Configuration\Configuration; |
|
16
|
|
|
use Zenify\DoctrineMigrations\DI\MigrationsExtension; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
final class BeforeCompileTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var MigrationsExtension |
|
24
|
|
|
*/ |
|
25
|
|
|
private $extension; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ContainerBuilder |
|
29
|
|
|
*/ |
|
30
|
|
|
private $containerBuilder; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
protected function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->extension = new MigrationsExtension; |
|
36
|
|
|
|
|
37
|
|
|
$this->containerBuilder = new ContainerBuilder; |
|
38
|
|
|
$this->containerBuilder->parameters = ['appDir' => __DIR__]; |
|
39
|
|
|
$this->containerBuilder->addDefinition('console', (new ServiceDefinition)->setClass(Application::class)); |
|
40
|
|
|
|
|
41
|
|
|
$compiler = new Compiler($this->containerBuilder); |
|
42
|
|
|
$compiler->addExtension('eventDispatcher', new EventDispatcherExtension); |
|
43
|
|
|
|
|
44
|
|
|
$this->extension->setCompiler($compiler, 'migrations'); |
|
45
|
|
|
$this->extension->loadConfiguration(); |
|
46
|
|
|
$this->extension->beforeCompile(); |
|
47
|
|
|
|
|
48
|
|
|
$this->containerBuilder->prepareClassList(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testSetConfigurationToCommands() |
|
53
|
|
|
{ |
|
54
|
|
|
$executeCommandDefinition = $this->getDefinitionByType(ExecuteCommand::class); |
|
55
|
|
|
|
|
56
|
|
|
$this->matchDefinitionSetupStatement( |
|
57
|
|
|
$executeCommandDefinition->getSetup()[0], |
|
58
|
|
|
'setMigrationConfiguration', |
|
59
|
|
|
['@' . Configuration::class] |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function testLoadCommandsToApplication() |
|
65
|
|
|
{ |
|
66
|
|
|
$applicationDefinition = $this->getDefinitionByType(Application::class); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertCount(6, $applicationDefinition->getSetup()); |
|
69
|
|
|
$this->matchDefinitionSetupStatement( |
|
70
|
|
|
$applicationDefinition->getSetup()[0], |
|
71
|
|
|
'add', |
|
72
|
|
|
['@2_Doctrine_DBAL_Migrations_Tools_Console_Command_DiffCommand'] |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param Statement $statement |
|
79
|
|
|
* @param string $entity |
|
80
|
|
|
* @param array $arguments |
|
81
|
|
|
*/ |
|
82
|
|
|
private function matchDefinitionSetupStatement(Statement $statement, $entity, array $arguments) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->assertSame($entity, $statement->getEntity()); |
|
85
|
|
|
$this->assertSame($arguments, $statement->arguments); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $type |
|
91
|
|
|
* @return ServiceDefinition |
|
92
|
|
|
*/ |
|
93
|
|
|
private function getDefinitionByType($type) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->containerBuilder->getDefinition($this->containerBuilder->getByType($type)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|