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