|
1
|
|
|
<?php |
|
2
|
|
|
namespace ReddogsTest\Doctrine\Migrations; |
|
3
|
|
|
|
|
4
|
|
|
use Reddogs\Doctrine\Migrations\AbstractCommand; |
|
5
|
|
|
use Symfony\Component\Console\Application; |
|
6
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand as MigrationsCommand; |
|
7
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
|
8
|
|
|
use ZF\Console\Route; |
|
9
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\StringInput; |
|
12
|
|
|
|
|
13
|
|
|
class AbstractCommandTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
private $command, $application, $migrationsCommand, $configuration, $migrationsConfig, $output; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->application = $this->getMockBuilder(Application::class) |
|
21
|
|
|
->setMethods(['add', 'run']) |
|
22
|
|
|
->getMock(); |
|
23
|
|
|
$this->migrationsCommand = $this->getMockBuilder(MigrationsCommand::class) |
|
24
|
|
|
->disableOriginalConstructor() |
|
25
|
|
|
->setMethods(['setMigrationConfiguration']) |
|
26
|
|
|
->getMockForAbstractClass(); |
|
27
|
|
|
$this->configuration = $this->getMockBuilder(Configuration::class) |
|
28
|
|
|
->disableOriginalConstructor() |
|
29
|
|
|
->setMethods([ |
|
30
|
|
|
'setMigrationsNamespace', 'setMigrationsDirectory', 'setMigrationsTableName', |
|
31
|
|
|
'registerMigrationsFromDirectory' |
|
32
|
|
|
]) |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
|
|
35
|
|
|
$this->output = $this->createMock(OutputInterface::class); |
|
36
|
|
|
|
|
37
|
|
|
$this->migrationsConfig = [ |
|
38
|
|
|
'testKey' => [ |
|
39
|
|
|
'namespace' => 'TestNamespace', |
|
40
|
|
|
'directory' => 'path/to/migrations', |
|
41
|
|
|
'table_name' => 'test_tablename' |
|
42
|
|
|
] |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
$this->command = $this->getMockBuilder(AbstractCommand::class) |
|
46
|
|
|
->setMethods(['getInputCommand']) |
|
47
|
|
|
->setConstructorArgs([ |
|
48
|
|
|
$this->application, |
|
49
|
|
|
$this->migrationsCommand, |
|
50
|
|
|
$this->configuration, |
|
51
|
|
|
$this->output, |
|
52
|
|
|
$this->migrationsConfig, |
|
53
|
|
|
])->getMockForAbstractClass(); |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGetApplication() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertSame($this->application, $this->command->getApplication()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testGetMigrationsCommand() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertSame($this->migrationsCommand, $this->command->getMigrationsCommand()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGetConfiguration() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertSame($this->configuration, $this->command->getConfiguration()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetOutput() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->assertSame($this->output, $this->command->getOutput()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetMigrationsConfig() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->assertSame($this->migrationsConfig, $this->command->getMigrationsConfig()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testInvoke() |
|
83
|
|
|
{ |
|
84
|
|
|
$route = new Route('mogrations:test', 'mogrations:testroute <moduleName>'); |
|
85
|
|
|
$this->configuration->expects($this->once()) |
|
86
|
|
|
->method('setMigrationsNamespace') |
|
87
|
|
|
->with($this->equalTo('TestNamespace')); |
|
88
|
|
|
$this->configuration->expects($this->once()) |
|
89
|
|
|
->method('setMigrationsDirectory') |
|
90
|
|
|
->with($this->equalTo('path/to/migrations')); |
|
91
|
|
|
$this->configuration->expects($this->once()) |
|
92
|
|
|
->method('setMigrationsTableName') |
|
93
|
|
|
->with($this->equalTo('test_tablename')); |
|
94
|
|
|
$this->configuration->expects($this->once()) |
|
95
|
|
|
->method('registerMigrationsFromDirectory') |
|
96
|
|
|
->with($this->equalTo('path/to/migrations')); |
|
97
|
|
|
|
|
98
|
|
|
$this->migrationsCommand->expects($this->once()) |
|
99
|
|
|
->method('setMigrationConfiguration') |
|
100
|
|
|
->with($this->equalTo($this->configuration)); |
|
101
|
|
|
|
|
102
|
|
|
$this->application->expects($this->once()) |
|
103
|
|
|
->method('add') |
|
104
|
|
|
->with($this->identicalTo($this->migrationsCommand)); |
|
105
|
|
|
$this->application->expects($this->once()) |
|
106
|
|
|
->method('run') |
|
107
|
|
|
->with($this->isInstanceOf(StringInput::class), |
|
108
|
|
|
$this->identicalTo($this->output)); |
|
109
|
|
|
|
|
110
|
|
|
$this->command->expects($this->once()) |
|
111
|
|
|
->method('getInputCommand') |
|
112
|
|
|
->with($this->equalTo($route)) |
|
113
|
|
|
->will($this->returnValue('testInputCommand')); |
|
114
|
|
|
|
|
115
|
|
|
$route->match(['mogrations:testroute', 'testKey']); |
|
116
|
|
|
|
|
117
|
|
|
$console = $this->createMock(AdapterInterface::class); |
|
118
|
|
|
$this->command->__invoke($route, $console); |
|
119
|
|
|
} |
|
120
|
|
|
} |