1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the box project. |
7
|
|
|
* |
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
9
|
|
|
* Théo Fidry <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license that is bundled |
12
|
|
|
* with this source code in the file LICENSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace KevinGH\RequirementChecker; |
16
|
|
|
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use function ob_get_contents; |
19
|
|
|
use function preg_replace; |
20
|
|
|
use const PHP_VERSION; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @covers \KevinGH\RequirementChecker\Checker |
24
|
|
|
*/ |
25
|
|
|
class CheckerTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @dataProvider provideRequirements |
29
|
|
|
*/ |
30
|
|
|
public function test_it_can_check_requirements( |
31
|
|
|
RequirementCollection $requirements, |
32
|
|
|
int $verbosity, |
33
|
|
|
bool $expectedResult, |
34
|
|
|
string $expectedOutput |
35
|
|
|
): void { |
36
|
|
|
$actualResult = $requirements->evaluateRequirements(); |
37
|
|
|
|
38
|
|
|
ob_start(); |
39
|
|
|
Checker::printCheck( |
40
|
|
|
$expectedResult, |
41
|
|
|
new Printer( |
42
|
|
|
$verbosity, |
43
|
|
|
false |
44
|
|
|
), |
45
|
|
|
$requirements |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$actualOutput = ob_get_contents(); |
49
|
|
|
ob_end_clean(); |
50
|
|
|
|
51
|
|
|
$actualOutput = DisplayNormalizer::removeTrailingSpaces($actualOutput); |
|
|
|
|
52
|
|
|
$actualOutput = preg_replace( |
53
|
|
|
'~/.+/php.ini~', |
54
|
|
|
'/path/to/php.ini', |
55
|
|
|
$actualOutput |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->assertSame($expectedOutput, $actualOutput); |
59
|
|
|
$this->assertSame($expectedResult, $actualResult); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function provideRequirements() |
63
|
|
|
{ |
64
|
|
|
$phpVersion = PHP_VERSION; |
65
|
|
|
|
66
|
|
|
yield (function () use ($phpVersion) { |
67
|
|
|
return [ |
68
|
|
|
new RequirementCollection(), |
69
|
|
|
IO::VERBOSITY_DEBUG, |
70
|
|
|
true, |
71
|
|
|
<<<EOF |
72
|
|
|
|
73
|
|
|
Box Requirements Checker |
74
|
|
|
======================== |
75
|
|
|
|
76
|
|
|
> Using PHP $phpVersion |
77
|
|
|
> PHP is using the following php.ini file: |
78
|
|
|
/path/to/php.ini |
79
|
|
|
|
80
|
|
|
> No requirements found. |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
[OK] Your system is ready to run the application. |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
|
87
|
|
|
EOF |
88
|
|
|
]; |
89
|
|
|
})(); |
90
|
|
|
|
91
|
|
|
yield (function () use ($phpVersion) { |
92
|
|
|
return [ |
93
|
|
|
new RequirementCollection(), |
94
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
95
|
|
|
true, |
96
|
|
|
<<<EOF |
97
|
|
|
|
98
|
|
|
Box Requirements Checker |
99
|
|
|
======================== |
100
|
|
|
|
101
|
|
|
> Using PHP $phpVersion |
102
|
|
|
> PHP is using the following php.ini file: |
103
|
|
|
/path/to/php.ini |
104
|
|
|
|
105
|
|
|
> No requirements found. |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
[OK] Your system is ready to run the application. |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
|
112
|
|
|
EOF |
113
|
|
|
]; |
114
|
|
|
})(); |
115
|
|
|
|
116
|
|
|
foreach ([IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL, IO::VERBOSITY_QUIET] as $verbosity) { |
117
|
|
|
yield (function () use ($verbosity) { |
118
|
|
|
return [ |
119
|
|
|
new RequirementCollection(), |
120
|
|
|
$verbosity, |
121
|
|
|
true, |
122
|
|
|
'', |
123
|
|
|
]; |
124
|
|
|
})(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
yield (function () use ($phpVersion) { |
128
|
|
|
$requirements = new RequirementCollection(); |
129
|
|
|
|
130
|
|
|
$requirements->addRequirement( |
131
|
|
|
'return true;', |
132
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
133
|
|
|
'The application requires the version "7.2.0" or greater.' |
134
|
|
|
); |
135
|
|
|
$requirements->addRequirement( |
136
|
|
|
'return true;', |
137
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
138
|
|
|
'The package "acme/foo" requires the extension "random".' |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
return [ |
142
|
|
|
$requirements, |
143
|
|
|
IO::VERBOSITY_DEBUG, |
144
|
|
|
true, |
145
|
|
|
<<<EOF |
146
|
|
|
|
147
|
|
|
Box Requirements Checker |
148
|
|
|
======================== |
149
|
|
|
|
150
|
|
|
> Using PHP $phpVersion |
151
|
|
|
> PHP is using the following php.ini file: |
152
|
|
|
/path/to/php.ini |
153
|
|
|
|
154
|
|
|
> Checking Box requirements: |
155
|
|
|
✔ The application requires the version "7.2.0" or greater. |
156
|
|
|
✔ The package "acme/foo" requires the extension "random". |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
[OK] Your system is ready to run the application. |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
|
EOF |
164
|
|
|
]; |
165
|
|
|
})(); |
166
|
|
|
|
167
|
|
|
yield (function () use ($phpVersion) { |
168
|
|
|
$requirements = new RequirementCollection(); |
169
|
|
|
|
170
|
|
|
$requirements->addRequirement( |
171
|
|
|
'return true;', |
172
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
173
|
|
|
'The application requires the version "7.2.0" or greater.' |
174
|
|
|
); |
175
|
|
|
$requirements->addRequirement( |
176
|
|
|
'return true;', |
177
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
178
|
|
|
'The package "acme/foo" requires the extension "random".' |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
return [ |
182
|
|
|
$requirements, |
183
|
|
|
IO::VERBOSITY_VERY_VERBOSE, |
184
|
|
|
true, |
185
|
|
|
<<<EOF |
186
|
|
|
|
187
|
|
|
Box Requirements Checker |
188
|
|
|
======================== |
189
|
|
|
|
190
|
|
|
> Using PHP $phpVersion |
191
|
|
|
> PHP is using the following php.ini file: |
192
|
|
|
/path/to/php.ini |
193
|
|
|
|
194
|
|
|
> Checking Box requirements: |
195
|
|
|
.. |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
[OK] Your system is ready to run the application. |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
|
202
|
|
|
EOF |
203
|
|
|
]; |
204
|
|
|
})(); |
205
|
|
|
|
206
|
|
|
foreach ([IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL, IO::VERBOSITY_QUIET] as $verbosity) { |
207
|
|
|
yield (function () use ($verbosity) { |
208
|
|
|
$requirements = new RequirementCollection(); |
209
|
|
|
|
210
|
|
|
$requirements->addRequirement( |
211
|
|
|
'return true;', |
212
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
213
|
|
|
'The application requires the version "7.2.0" or greater.' |
214
|
|
|
); |
215
|
|
|
$requirements->addRequirement( |
216
|
|
|
'return true;', |
217
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
218
|
|
|
'The package "acme/foo" requires the extension "random".' |
219
|
|
|
); |
220
|
|
|
|
221
|
|
|
return [ |
222
|
|
|
$requirements, |
223
|
|
|
$verbosity, |
224
|
|
|
true, |
225
|
|
|
'', |
226
|
|
|
]; |
227
|
|
|
})(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
yield (function () use ($phpVersion) { |
231
|
|
|
$requirements = new RequirementCollection(); |
232
|
|
|
|
233
|
|
|
$requirements->addRequirement( |
234
|
|
|
'return true;', |
235
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
236
|
|
|
'The application requires the version "7.2.0" or greater.' |
237
|
|
|
); |
238
|
|
|
$requirements->addRequirement( |
239
|
|
|
'return false;', |
240
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
241
|
|
|
'The package "acme/foo" requires the extension "random".' |
242
|
|
|
); |
243
|
|
|
|
244
|
|
|
return [ |
245
|
|
|
$requirements, |
246
|
|
|
IO::VERBOSITY_DEBUG, |
247
|
|
|
false, |
248
|
|
|
<<<EOF |
249
|
|
|
|
250
|
|
|
Box Requirements Checker |
251
|
|
|
======================== |
252
|
|
|
|
253
|
|
|
> Using PHP $phpVersion |
254
|
|
|
> PHP is using the following php.ini file: |
255
|
|
|
/path/to/php.ini |
256
|
|
|
|
257
|
|
|
> Checking Box requirements: |
258
|
|
|
✔ The application requires the version "7.2.0" or greater. |
259
|
|
|
✘ The package "acme/foo" requires the extension "random". Enable it or install |
260
|
|
|
a polyfill. |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
[ERROR] Your system is not ready to run the application. |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
Fix the following mandatory requirements: |
267
|
|
|
========================================= |
268
|
|
|
|
269
|
|
|
* The package "acme/foo" requires the extension "random". Enable it or install |
270
|
|
|
a polyfill. |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
EOF |
274
|
|
|
]; |
275
|
|
|
})(); |
276
|
|
|
|
277
|
|
|
foreach ([IO::VERBOSITY_VERY_VERBOSE, IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL] as $verbosity) { |
278
|
|
|
yield (function () use ($verbosity, $phpVersion) { |
279
|
|
|
$requirements = new RequirementCollection(); |
280
|
|
|
|
281
|
|
|
$requirements->addRequirement( |
282
|
|
|
'return true;', |
283
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
284
|
|
|
'The application requires the version "7.2.0" or greater.' |
285
|
|
|
); |
286
|
|
|
$requirements->addRequirement( |
287
|
|
|
'return false;', |
288
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
289
|
|
|
'The package "acme/foo" requires the extension "random".' |
290
|
|
|
); |
291
|
|
|
|
292
|
|
|
return [ |
293
|
|
|
$requirements, |
294
|
|
|
$verbosity, |
295
|
|
|
false, |
296
|
|
|
<<<EOF |
297
|
|
|
|
298
|
|
|
Box Requirements Checker |
299
|
|
|
======================== |
300
|
|
|
|
301
|
|
|
> Using PHP $phpVersion |
302
|
|
|
> PHP is using the following php.ini file: |
303
|
|
|
/path/to/php.ini |
304
|
|
|
|
305
|
|
|
> Checking Box requirements: |
306
|
|
|
.E |
307
|
|
|
|
308
|
|
|
|
309
|
|
|
[ERROR] Your system is not ready to run the application. |
310
|
|
|
|
311
|
|
|
|
312
|
|
|
Fix the following mandatory requirements: |
313
|
|
|
========================================= |
314
|
|
|
|
315
|
|
|
* The package "acme/foo" requires the extension "random". Enable it or install |
316
|
|
|
a polyfill. |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
EOF |
320
|
|
|
]; |
321
|
|
|
})(); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
yield (function () use ($phpVersion) { |
325
|
|
|
$requirements = new RequirementCollection(); |
326
|
|
|
|
327
|
|
|
$requirements->addRequirement( |
328
|
|
|
'return true;', |
329
|
|
|
'The application requires the version "7.2.0" or greater. Got "7.2.2"', |
330
|
|
|
'The application requires the version "7.2.0" or greater.' |
331
|
|
|
); |
332
|
|
|
$requirements->addRequirement( |
333
|
|
|
'return false;', |
334
|
|
|
'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.', |
335
|
|
|
'The package "acme/foo" requires the extension "random".' |
336
|
|
|
); |
337
|
|
|
|
338
|
|
|
return [ |
339
|
|
|
$requirements, |
340
|
|
|
IO::VERBOSITY_QUIET, |
341
|
|
|
false, |
342
|
|
|
<<<EOF |
343
|
|
|
|
344
|
|
|
Box Requirements Checker |
345
|
|
|
======================== |
346
|
|
|
|
347
|
|
|
> Using PHP $phpVersion |
348
|
|
|
> PHP is using the following php.ini file: |
349
|
|
|
/path/to/php.ini |
350
|
|
|
|
351
|
|
|
> Checking Box requirements: |
352
|
|
|
.E |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
[ERROR] Your system is not ready to run the application. |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
Fix the following mandatory requirements: |
359
|
|
|
========================================= |
360
|
|
|
|
361
|
|
|
* The package "acme/foo" requires the extension "random". Enable it or install |
362
|
|
|
a polyfill. |
363
|
|
|
|
364
|
|
|
|
365
|
|
|
EOF |
366
|
|
|
]; |
367
|
|
|
})(); |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths