1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
include_once(__DIR__.'/CommandTest.php'); |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Tests the 'migrate' as well as the 'migration' command |
9
|
|
|
*/ |
10
|
|
|
class MigrateTest extends CommandTest |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param string $filePath |
14
|
|
|
* @dataProvider goodDSLProvider |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
public function testExecuteGoodDSL($filePath = '') |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
if ($filePath == '') { |
19
|
|
|
$this->markTestSkipped(); |
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// Make user migration is not in the db: delete it, ignoring errors |
24
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true)); |
25
|
|
|
$exitCode = $this->app->run($input, $this->output); |
|
|
|
|
26
|
|
|
$output = $this->output->fetch(); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true)); |
29
|
|
|
$exitCode = $this->app->run($input, $this->output); |
30
|
|
|
$output = $this->output->fetch(); |
31
|
|
|
$this->assertSame(0, $exitCode); |
32
|
|
|
$this->assertRegexp('?Added migration?', $output); |
33
|
|
|
|
34
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true)); |
35
|
|
|
$exitCode = $this->app->run($input, $this->output); |
36
|
|
|
$output = $this->output->fetch(); |
37
|
|
|
$this->assertSame(0, $exitCode); |
38
|
|
|
// check that there are no notes after adding the migration |
39
|
|
|
$this->assertRegexp('?\| ' . basename($filePath) . ' +\| +\|?', $output); |
40
|
|
|
|
41
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true)); |
42
|
|
|
$exitCode = $this->app->run($input, $this->output); |
43
|
|
|
$output = $this->output->fetch(); |
|
|
|
|
44
|
|
|
$this->assertSame(0, $exitCode); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $filePath |
49
|
|
|
* @dataProvider badDSLProvider |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function testExecuteBadDSL($filePath = '') |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
if ($filePath == '') { |
54
|
|
|
$this->markTestSkipped(); |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Make user migration is not in the db: delete it, ignoring errors |
59
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true)); |
60
|
|
|
$exitCode = $this->app->run($input, $this->output); |
|
|
|
|
61
|
|
|
$output = $this->output->fetch(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true)); |
64
|
|
|
$exitCode = $this->app->run($input, $this->output); |
65
|
|
|
$output = $this->output->fetch(); |
66
|
|
|
$this->assertSame(0, $exitCode); |
67
|
|
|
$this->assertRegexp('?Added migration?', $output); |
68
|
|
|
|
69
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true)); |
70
|
|
|
$exitCode = $this->app->run($input, $this->output); |
71
|
|
|
$output = $this->output->fetch(); |
72
|
|
|
$this->assertSame(0, $exitCode); |
73
|
|
|
// check that there are no notes after adding the migration |
74
|
|
|
$this->assertRegexp('?Skipping ' . basename($filePath) . '?', $output); |
75
|
|
|
|
76
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true)); |
77
|
|
|
$exitCode = $this->app->run($input, $this->output); |
78
|
|
|
$output = $this->output->fetch(); |
|
|
|
|
79
|
|
|
$this->assertSame(0, $exitCode); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function goodDSLProvider() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$dslDir = $this->dslDir.'/good'; |
85
|
|
|
$out = array(); |
86
|
|
|
foreach(scandir($dslDir) as $fileName) { |
87
|
|
|
$filePath = $dslDir . '/' . $fileName; |
88
|
|
|
if (is_file($filePath)) { |
89
|
|
|
$out[] = array($filePath); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
return $out; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
public function badDSLProvider() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$dslDir = $this->dslDir.'/bad'; |
98
|
|
|
$out = array(); |
99
|
|
|
foreach(scandir($dslDir) as $fileName) { |
100
|
|
|
$filePath = $dslDir . '/' . $fileName; |
101
|
|
|
if (is_file($filePath)) { |
102
|
|
|
$out[] = array($filePath); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
return $out; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.