1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
include_once(__DIR__.'/CommandTest.php'); |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
6
|
|
|
|
7
|
|
|
class GenerateTest extends CommandTest |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @todo add tests for generating a 'role' migration |
11
|
|
|
*/ |
12
|
|
|
public function testGenerateDSL() |
13
|
|
|
{ |
14
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle)); |
15
|
|
|
$exitCode = $this->app->run($input, $this->output); |
16
|
|
|
$output = $this->output->fetch(); |
17
|
|
|
$this->assertSame(0, $exitCode); |
18
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
19
|
|
|
|
20
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle, '--format' => 'sql')); |
21
|
|
|
$exitCode = $this->app->run($input, $this->output); |
22
|
|
|
$output = $this->output->fetch(); |
23
|
|
|
$this->assertSame(0, $exitCode); |
24
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
25
|
|
|
|
26
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle, '--format' => 'php')); |
27
|
|
|
$exitCode = $this->app->run($input, $this->output); |
28
|
|
|
$output = $this->output->fetch(); |
29
|
|
|
$this->assertSame(0, $exitCode); |
30
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
31
|
|
|
|
32
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle, 'name' => 'unit_test_generated')); |
33
|
|
|
$exitCode = $this->app->run($input, $this->output); |
34
|
|
|
$output = $this->output->fetch(); |
35
|
|
|
$this->assertSame(0, $exitCode); |
36
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
37
|
|
|
|
38
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle, 'name' => 'unit_test_generated', '--format' => 'sql')); |
39
|
|
|
$exitCode = $this->app->run($input, $this->output); |
40
|
|
|
$output = $this->output->fetch(); |
41
|
|
|
$this->assertSame(0, $exitCode); |
42
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
43
|
|
|
|
44
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:generate', 'bundle' => $this->targetBundle, 'name' => 'unit_test_generated', '--format' => 'php')); |
45
|
|
|
$exitCode = $this->app->run($input, $this->output); |
46
|
|
|
$output = $this->output->fetch(); |
47
|
|
|
$this->assertSame(0, $exitCode); |
48
|
|
|
$this->checkGeneratedFile($this->saveGeneratedFile($output)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function saveGeneratedFile($output) |
52
|
|
|
{ |
53
|
|
|
if (preg_match('/Generated new migration file: +(.*)/', $output, $matches)) { |
54
|
|
|
$this->leftovers[] = $matches[1]; |
55
|
|
|
return $matches[1]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function checkGeneratedFile($filePath) |
62
|
|
|
{ |
63
|
|
|
$input = new ArrayInput(array('command' => 'kaliop:migration:status')); |
64
|
|
|
$exitCode = $this->app->run($input, $this->output); |
65
|
|
|
$output = $this->output->fetch(); |
66
|
|
|
$this->assertSame(0, $exitCode); |
67
|
|
|
$this->assertRegExp('?\| ' . basename($filePath) . ' +\| not executed \|?', $output ); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.