1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use AmaTeam\Image\Projection\Test\Support\Fixture\Projection\Manager; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @SuppressWarnings(PHPMD) |
7
|
|
|
*/ |
8
|
|
|
class RoboFile extends \Robo\Tasks // NOSONAR |
9
|
|
|
{ |
10
|
|
|
const COVERAGE_OPTION = 'coverage'; |
11
|
|
|
const DEFAULT_TEST_OPTIONS = ['coverage' => false]; |
12
|
|
|
const COVERAGE_DIRECTORY = 'Coverage'; |
13
|
|
|
|
14
|
|
|
public function testSetup() |
15
|
|
|
{ |
16
|
|
|
$this |
17
|
|
|
->taskFilesystemStack() |
18
|
|
|
->mkdir(self::testsMetadataDir()) |
19
|
|
|
->run() |
20
|
|
|
->stopOnFail(); |
21
|
|
|
$this |
22
|
|
|
->taskExecStack() |
23
|
|
|
->exec([self::binary('codecept'), 'build']) |
24
|
|
|
->run() |
25
|
|
|
->stopOnFail(); |
26
|
|
|
$manager = new Manager(); |
27
|
|
|
$manager->install(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
private function runTests($suite = null, array $options = self::DEFAULT_TEST_OPTIONS) |
31
|
|
|
{ |
32
|
|
|
$suite = $suite ? self::normalizeTestSuite($suite) : null; |
33
|
|
|
$directory = $suite ? ['Suite', $suite] : []; |
34
|
|
|
$coverageDir = $directory; |
35
|
|
|
$coverageDir[] = self::COVERAGE_DIRECTORY; |
36
|
|
|
$this |
37
|
|
|
->taskFilesystemStack() |
38
|
|
|
->mkdir(self::testsMetadataDir($coverageDir)) |
39
|
|
|
->run() |
40
|
|
|
->stopOnFail(); |
41
|
|
|
$task = $this |
42
|
|
|
->taskCodecept(self::binary('codecept')) |
43
|
|
|
->suite($suite) |
44
|
|
|
->xml(self::testsMetadataDir(array_merge($directory, ['junit.xml']))) |
45
|
|
|
->debug(); |
46
|
|
|
if ($options[self::COVERAGE_OPTION]) { |
47
|
|
|
$task |
48
|
|
|
->coverage(self::testsMetadataDir(array_merge($coverageDir, ['coverage.cov']))) |
49
|
|
|
->coverageXml(self::testsMetadataDir(array_merge($coverageDir, ['coverage.xml']))); |
50
|
|
|
} |
51
|
|
|
return $task->run(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testUnit($options = self::DEFAULT_TEST_OPTIONS) |
55
|
|
|
{ |
56
|
|
|
return $this->runTests('Unit', $options); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testFunctional($options = self::DEFAULT_TEST_OPTIONS) |
60
|
|
|
{ |
61
|
|
|
return $this->runTests('Functional', $options); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testIntegration($options = self::DEFAULT_TEST_OPTIONS) |
65
|
|
|
{ |
66
|
|
|
return $this->runTests('Integration', $options); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testAcceptance($options = self::DEFAULT_TEST_OPTIONS) |
70
|
|
|
{ |
71
|
|
|
return $this->runTests('Acceptance', $options); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function test() |
75
|
|
|
{ |
76
|
|
|
$this->testClean()->stopOnFail(); |
77
|
|
|
$this->runTests()->stopOnFail(); |
78
|
|
|
return $this->coverageReport(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testClean() |
82
|
|
|
{ |
83
|
|
|
return $this |
84
|
|
|
->taskCleanDir([ |
85
|
|
|
self::testsReportDir(), |
86
|
|
|
self::testsMetadataDir() |
87
|
|
|
]) |
88
|
|
|
->run(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testReport() |
92
|
|
|
{ |
93
|
|
|
$this->coverageReport()->stopOnFail(); |
94
|
|
|
return $this->allureReport(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function allureReport() |
98
|
|
|
{ |
99
|
|
|
$command = [ |
100
|
|
|
'allure', |
101
|
|
|
'generate', |
102
|
|
|
'--clean', |
103
|
|
|
'-o', |
104
|
|
|
self::testsReportDir(['Allure']), |
105
|
|
|
'--', |
106
|
|
|
self::testsMetadataDir(['Allure']) |
107
|
|
|
]; |
108
|
|
|
return $this |
109
|
|
|
->taskExecStack() |
110
|
|
|
->exec($command) |
111
|
|
|
->run(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function coveragePublish($suite = null) |
115
|
|
|
{ |
116
|
|
|
$suite = self::normalizeTestSuite($suite); |
117
|
|
|
$directory = $suite ? ['Suite', $suite] : []; |
118
|
|
|
$path = array_merge($directory, ['Coverage', 'coverage.xml']); |
119
|
|
|
$this |
120
|
|
|
->taskExecStack() |
121
|
|
|
->exec([ |
122
|
|
|
self::binary('coveralls'), |
123
|
|
|
'-x', |
124
|
|
|
self::testsMetadataDir($path) |
125
|
|
|
]) |
126
|
|
|
->run(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function coverageReport() |
130
|
|
|
{ |
131
|
|
|
$command = [ |
132
|
|
|
self::binary('phpcov'), |
133
|
|
|
'merge', |
134
|
|
|
'--html', |
135
|
|
|
self::testsReportDir([self::COVERAGE_DIRECTORY]), |
136
|
|
|
'--', |
137
|
|
|
self::testsMetadataDir() |
138
|
|
|
]; |
139
|
|
|
return $this |
140
|
|
|
->taskExecStack() |
141
|
|
|
->exec($command) |
142
|
|
|
->run(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function lint() |
146
|
|
|
{ |
147
|
|
|
$rules = self::path(['res', 'phpmd', 'rules.xml']); |
148
|
|
|
$mdBinary = self::binary('phpmd'); |
149
|
|
|
$commands = [ |
150
|
|
|
[ |
151
|
|
|
self::binary('phpcs'), |
152
|
|
|
'--standard=PSR2', |
153
|
|
|
self::sourcesDir() |
154
|
|
|
], |
155
|
|
|
[ |
156
|
|
|
$mdBinary, |
157
|
|
|
self::sourcesDir(), |
158
|
|
|
'html', |
159
|
|
|
$rules, |
160
|
|
|
'--reportfile', |
161
|
|
|
self::testsReportDir(['Lint', 'phpmd.html']) |
162
|
|
|
], |
163
|
|
|
[ |
164
|
|
|
$mdBinary, |
165
|
|
|
self::sourcesDir(), |
166
|
|
|
'text', |
167
|
|
|
$rules, |
168
|
|
|
] |
169
|
|
|
]; |
170
|
|
|
$this |
171
|
|
|
->taskFilesystemStack() |
172
|
|
|
->mkdir(self::testsReportDir(['Lint'])) |
173
|
|
|
->run(); |
174
|
|
|
$executor = $this |
175
|
|
|
->taskParallelExec() |
176
|
|
|
->printed(); |
177
|
|
|
foreach ($commands as $command) { |
178
|
|
|
$command = array_map('escapeshellarg', $command); |
179
|
|
|
$executor->process(implode(' ', $command)); |
180
|
|
|
} |
181
|
|
|
return $executor->run(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
private static function path(array $path = []) |
185
|
|
|
{ |
186
|
|
|
array_unshift($path, __DIR__); |
187
|
|
|
return implode(DIRECTORY_SEPARATOR, $path); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
private static function sourcesDir(array $path = []) |
191
|
|
|
{ |
192
|
|
|
array_unshift($path, 'src'); |
193
|
|
|
return self::path($path); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
private static function testsDir(array $path = []) |
197
|
|
|
{ |
198
|
|
|
array_unshift($path, 'tests'); |
199
|
|
|
return self::path($path); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
private static function testsMetadataDir(array $path = []) |
203
|
|
|
{ |
204
|
|
|
array_unshift($path, 'Metadata'); |
205
|
|
|
return self::testsDir($path); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
private static function testsReportDir(array $path = []) |
209
|
|
|
{ |
210
|
|
|
array_unshift($path, 'Report'); |
211
|
|
|
return self::testsDir($path); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
private static function binary($name) |
215
|
|
|
{ |
216
|
|
|
return self::path(['bin', $name]); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
private static function normalizeTestSuite($suite) |
220
|
|
|
{ |
221
|
|
|
if (!$suite) { |
222
|
|
|
return null; |
223
|
|
|
} |
224
|
|
|
return strtoupper($suite[0]) . strtolower(substr($suite, 1)); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|