|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ReddogsTest\Doctrine\Migrations; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
|
6
|
|
|
use Doctrine\DBAL\Migrations\Migration; |
|
7
|
|
|
use Doctrine\DBAL\Migrations\OutputWriter; |
|
8
|
|
|
use Reddogs\Doctrine\Migrations\MigrateAllCommand; |
|
9
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
|
10
|
|
|
use ZF\Console\Route; |
|
11
|
|
|
|
|
12
|
|
|
class MigrateAllCommandTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $configurations, $migrations, $configuration, $migration; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
protected function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->configuration = $this->getMockBuilder(Configuration::class) |
|
19
|
|
|
->disableOriginalConstructor() |
|
20
|
|
|
->setMethods(['createMigrationTable', 'setOutputWriter']) |
|
21
|
|
|
->getMock();; |
|
22
|
|
|
$this->configurations = ['testKey' => $this->configuration]; |
|
23
|
|
|
|
|
24
|
|
|
$this->migration = $this->getMockBuilder(Migration::class) |
|
25
|
|
|
->disableOriginalConstructor() |
|
26
|
|
|
->setMethods(['migrate']) |
|
27
|
|
|
->getMock(); |
|
28
|
|
|
$this->migrations = ['testKey' => $this->migration]; |
|
29
|
|
|
|
|
30
|
|
|
$this->command = new MigrateAllCommand($this->configurations, $this->migrations); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGetConfigurations() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->assertSame($this->configurations, $this->command->getConfigurations()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetMigrations() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertSame($this->migrations, $this->command->getMigrations()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testInvoke() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->configuration->expects($this->once()) |
|
46
|
|
|
->method('createMigrationTable'); |
|
47
|
|
|
|
|
48
|
|
|
$this->configuration->expects($this->once()) |
|
49
|
|
|
->method('setOutputWriter') |
|
50
|
|
|
->with($this->isInstanceOf(OutputWriter::class)); |
|
51
|
|
|
|
|
52
|
|
|
$this->migration->expects($this->once()) |
|
53
|
|
|
->method('migrate') |
|
54
|
|
|
->will($this->returnValue(['some result line'])); |
|
55
|
|
|
|
|
56
|
|
|
$route = new Route('mogrations:migrate-all', 'mogrations:migrate-all <moduleName>'); |
|
57
|
|
|
$adapter = $this->createMock(AdapterInterface::class); |
|
58
|
|
|
$this->command->__invoke($route, $adapter); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testInvokeEmptyResultOutputsInfo() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->configuration->expects($this->once()) |
|
64
|
|
|
->method('createMigrationTable'); |
|
65
|
|
|
|
|
66
|
|
|
$this->configuration->expects($this->once()) |
|
67
|
|
|
->method('setOutputWriter') |
|
68
|
|
|
->with($this->isInstanceOf(OutputWriter::class)); |
|
69
|
|
|
|
|
70
|
|
|
$this->migration->expects($this->once()) |
|
71
|
|
|
->method('migrate') |
|
72
|
|
|
->will($this->returnValue([])); |
|
73
|
|
|
|
|
74
|
|
|
$route = new Route('mogrations:migrate-all', 'mogrations:migrate-all <moduleName>'); |
|
75
|
|
|
$adapter = $this->getMockBuilder(AdapterInterface::class) |
|
76
|
|
|
->setMethods(['writeLine']) |
|
77
|
|
|
->getMockForAbstractClass(); |
|
78
|
|
|
|
|
79
|
|
|
$adapter->expects($this->once()) |
|
80
|
|
|
->method('writeLine') |
|
81
|
|
|
->with($this->equalTo('module \'testKey\': no migrations to execute')); |
|
82
|
|
|
$this->command->__invoke($route, $adapter); |
|
83
|
|
|
} |
|
84
|
|
|
} |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.