Completed
Push — master ( 48cda2...12f48c )
by Gaetano
07:13
created

MigrateTest::invalidDSLProvider()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 10
c 1
b 0
f 1
nc 4
nop 0
dl 16
loc 16
rs 9.2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 3.

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.

Loading history...
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    /**
13
     * @param string $filePath
14
     * @dataProvider goodDSLProvider
15
     */
16
    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
        $this->app->run($input, $this->output);
26
        $this->fetchOutput();
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->fetchOutput();
31
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
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->fetchOutput();
37
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
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->fetchOutput();
44
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
45
    }
46
    /**
47
     * @param string $filePath
48
     * @dataProvider invalidDSLProvider
49
     */
50
    public function testExecuteInvalidDSL($filePath = '')
51
    {
52
        if ($filePath == '') {
53
            $this->markTestSkipped();
54
            return;
55
        }
56
57
        // Make user migration is not in the db: delete it, ignoring errors
58
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
59
        $this->app->run($input, $this->output);
60
        $this->fetchOutput();
61
62
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true));
63
        $exitCode = $this->app->run($input, $this->output);
64
        $output = $this->fetchOutput();
65
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
66
        $this->assertRegexp('?Added migration?', $output);
67
68
        $input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true));
69
        $exitCode = $this->app->run($input, $this->output);
70
        $output = $this->fetchOutput();
71
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
72
        // check that there are no notes after adding the migration
73
        $this->assertRegexp('?Skipping ' . basename($filePath) . '?', $output);
74
75
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
76
        $exitCode = $this->app->run($input, $this->output);
77
        $output = $this->fetchOutput();
78
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
79
    }
80
81
    /**
82
     * @param string $filePath
83
     * @dataProvider badDSLProvider
84
     */
85
    public function testExecuteBadDSL($filePath = '')
86
    {
87
        if ($filePath == '') {
88
            $this->markTestSkipped();
89
            return;
90
        }
91
92
        // Make user migration is not in the db: delete it, ignoring errors
93
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
94
        $this->app->run($input, $this->output);
95
        $this->fetchOutput();
96
97
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => $filePath, '--add' => true, '-n' => true));
98
        $exitCode = $this->app->run($input, $this->output);
99
        $output = $this->fetchOutput();
100
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
101
        $this->assertRegexp('?Added migration?', $output);
102
103
        $input = new ArrayInput(array('command' => 'kaliop:migration:migrate', '--path' => array($filePath), '-n' => true));
104
        $exitCode = $this->app->run($input, $this->output);
105
        $output = $this->fetchOutput();
106
        $this->assertNotSame(0, $exitCode, 'CLI Command should have failed. Output: ' . $output);
107
        // check that there are no notes after adding the migration
108
        $this->assertRegexp('?Migration aborted.?', $output);
109
110
        $input = new ArrayInput(array('command' => 'kaliop:migration:migration', 'migration' => basename($filePath), '--delete' => true, '-n' => true));
111
        $exitCode = $this->app->run($input, $this->output);
112
        $output = $this->fetchOutput();
113
        $this->assertSame(0, $exitCode, 'CLI Command failed. Output: ' . $output);
114
    }
115
116 View Code Duplication
    public function goodDSLProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $dslDir = $this->dslDir.'/good';
119
        if(!is_dir($dslDir)) {
120
            return array();
121
        }
122
123
        $out = array();
124
        foreach(scandir($dslDir) as $fileName) {
125
            $filePath = $dslDir . '/' . $fileName;
126
            if (is_file($filePath)) {
127
                $out[] = array($filePath);
128
            }
129
        }
130
        return $out;
131
    }
132
133 View Code Duplication
    public function invalidDSLProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        $dslDir = $this->dslDir.'/bad/parsing';
136
        if(!is_dir($dslDir)) {
137
            return array();
138
        }
139
140
        $out = array();
141
        foreach(scandir($dslDir) as $fileName) {
142
            $filePath = $dslDir . '/' . $fileName;
143
            if (is_file($filePath)) {
144
                $out[] = array($filePath);
145
            }
146
        }
147
        return $out;
148
    }
149
150 View Code Duplication
    public function badDSLProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
    {
152
        $dslDir = $this->dslDir.'/bad/execution';
153
        if(!is_dir($dslDir)) {
154
            return array();
155
        }
156
157
        $out = array();
158
        foreach(scandir($dslDir) as $fileName) {
159
            $filePath = $dslDir . '/' . $fileName;
160
            if (is_file($filePath)) {
161
                $out[] = array($filePath);
162
            }
163
        }
164
        return $out;
165
    }
166
}
167