Passed
Push — master ( 8bd994...8bfb27 )
by Théo
02:28
created

ts/CheckerTest.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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);
1 ignored issue
show
Bug introduced by
The type KevinGH\RequirementChecker\DisplayNormalizer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
                new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

131
                /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
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
                new class implements IsFulfilled {
0 ignored issues
show
Bug introduced by
new ClassNode() of type anonymous//requirement-c...tests/CheckerTest.php$0 is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

136
                /** @scrutinizer ignore-type */ new class implements IsFulfilled {
Loading history...
137
                    public function __invoke()
138
                    {
139
                        return true;
140
                    }
141
                },
142
                'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
143
                'The package "acme/foo" requires the extension "random".'
144
            );
145
146
            return [
147
                $requirements,
148
                IO::VERBOSITY_DEBUG,
149
                true,
150
                <<<EOF
151
152
Box Requirements Checker
153
========================
154
155
> Using PHP $phpVersion
156
> PHP is using the following php.ini file:
157
  /path/to/php.ini
158
159
> Checking Box requirements:
160
  ✔ The application requires the version "7.2.0" or greater.
161
  ✔ The package "acme/foo" requires the extension "random".
162
163
164
 [OK] Your system is ready to run the application.
165
166
167
168
EOF
169
            ];
170
        })();
171
172
        yield (function () use ($phpVersion) {
173
            $requirements = new RequirementCollection();
174
175
            $requirements->addRequirement(
176
                new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

176
                /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
177
                'The application requires the version "7.2.0" or greater. Got "7.2.2"',
178
                'The application requires the version "7.2.0" or greater.'
179
            );
180
            $requirements->addRequirement(
181
                new ConditionIsFulfilled(),
182
                'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
183
                'The package "acme/foo" requires the extension "random".'
184
            );
185
186
            return [
187
                $requirements,
188
                IO::VERBOSITY_VERY_VERBOSE,
189
                true,
190
                <<<EOF
191
192
Box Requirements Checker
193
========================
194
195
> Using PHP $phpVersion
196
> PHP is using the following php.ini file:
197
  /path/to/php.ini
198
199
> Checking Box requirements:
200
  ..
201
202
203
 [OK] Your system is ready to run the application.
204
205
206
207
EOF
208
            ];
209
        })();
210
211
        foreach ([IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL, IO::VERBOSITY_QUIET] as $verbosity) {
212
            yield (function () use ($verbosity) {
213
                $requirements = new RequirementCollection();
214
215
                $requirements->addRequirement(
216
                    new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

216
                    /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
217
                    'The application requires the version "7.2.0" or greater. Got "7.2.2"',
218
                    'The application requires the version "7.2.0" or greater.'
219
                );
220
                $requirements->addRequirement(
221
                    new ConditionIsFulfilled(),
222
                    'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
223
                    'The package "acme/foo" requires the extension "random".'
224
                );
225
226
                return [
227
                    $requirements,
228
                    $verbosity,
229
                    true,
230
                    '',
231
                ];
232
            })();
233
        }
234
235
        yield (function () use ($phpVersion) {
236
            $requirements = new RequirementCollection();
237
238
            $requirements->addRequirement(
239
                new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

239
                /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
240
                'The application requires the version "7.2.0" or greater. Got "7.2.2"',
241
                'The application requires the version "7.2.0" or greater.'
242
            );
243
            $requirements->addRequirement(
244
                new ConditionIsNotFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...nditionIsNotFulfilled() of type KevinGH\RequirementChecker\ConditionIsNotFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

244
                /** @scrutinizer ignore-type */ new ConditionIsNotFulfilled(),
Loading history...
245
                'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
246
                'The package "acme/foo" requires the extension "random".'
247
            );
248
249
            return [
250
                $requirements,
251
                IO::VERBOSITY_DEBUG,
252
                false,
253
                <<<EOF
254
255
Box Requirements Checker
256
========================
257
258
> Using PHP $phpVersion
259
> PHP is using the following php.ini file:
260
  /path/to/php.ini
261
262
> Checking Box requirements:
263
  ✔ The application requires the version "7.2.0" or greater.
264
  ✘ The package "acme/foo" requires the extension "random". Enable it or install
265
a polyfill.
266
267
268
 [ERROR] Your system is not ready to run the application.
269
270
271
Fix the following mandatory requirements:
272
=========================================
273
274
 * The package "acme/foo" requires the extension "random". Enable it or install
275
   a polyfill.
276
277
278
EOF
279
            ];
280
        })();
281
282
        foreach ([IO::VERBOSITY_VERY_VERBOSE, IO::VERBOSITY_VERBOSE, IO::VERBOSITY_NORMAL] as $verbosity) {
283
            yield (function () use ($verbosity, $phpVersion) {
284
                $requirements = new RequirementCollection();
285
286
                $requirements->addRequirement(
287
                    new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

287
                    /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
288
                    'The application requires the version "7.2.0" or greater. Got "7.2.2"',
289
                    'The application requires the version "7.2.0" or greater.'
290
                );
291
                $requirements->addRequirement(
292
                    new ConditionIsNotFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...nditionIsNotFulfilled() of type KevinGH\RequirementChecker\ConditionIsNotFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

292
                    /** @scrutinizer ignore-type */ new ConditionIsNotFulfilled(),
Loading history...
293
                    'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
294
                    'The package "acme/foo" requires the extension "random".'
295
                );
296
297
                return [
298
                    $requirements,
299
                    $verbosity,
300
                    false,
301
                    <<<EOF
302
303
Box Requirements Checker
304
========================
305
306
> Using PHP $phpVersion
307
> PHP is using the following php.ini file:
308
  /path/to/php.ini
309
310
> Checking Box requirements:
311
  .E
312
313
314
 [ERROR] Your system is not ready to run the application.
315
316
317
Fix the following mandatory requirements:
318
=========================================
319
320
 * The package "acme/foo" requires the extension "random". Enable it or install
321
   a polyfill.
322
323
324
EOF
325
                ];
326
            })();
327
        }
328
329
        yield (function () use ($phpVersion) {
330
            $requirements = new RequirementCollection();
331
332
            $requirements->addRequirement(
333
                new ConditionIsFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...\ConditionIsFulfilled() of type KevinGH\RequirementChecker\ConditionIsFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

333
                /** @scrutinizer ignore-type */ new ConditionIsFulfilled(),
Loading history...
334
                'The application requires the version "7.2.0" or greater. Got "7.2.2"',
335
                'The application requires the version "7.2.0" or greater.'
336
            );
337
            $requirements->addRequirement(
338
                new ConditionIsNotFulfilled(),
0 ignored issues
show
Bug introduced by
new KevinGH\RequirementC...nditionIsNotFulfilled() of type KevinGH\RequirementChecker\ConditionIsNotFulfilled is incompatible with the type string expected by parameter $checkIsFulfilled of KevinGH\RequirementCheck...ction::addRequirement(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

338
                /** @scrutinizer ignore-type */ new ConditionIsNotFulfilled(),
Loading history...
339
                'The package "acme/foo" requires the extension "random". Enable it or install a polyfill.',
340
                'The package "acme/foo" requires the extension "random".'
341
            );
342
343
            return [
344
                $requirements,
345
                IO::VERBOSITY_QUIET,
346
                false,
347
                <<<EOF
348
349
Box Requirements Checker
350
========================
351
352
> Using PHP $phpVersion
353
> PHP is using the following php.ini file:
354
  /path/to/php.ini
355
356
> Checking Box requirements:
357
  .E
358
359
360
 [ERROR] Your system is not ready to run the application.
361
362
363
Fix the following mandatory requirements:
364
=========================================
365
366
 * The package "acme/foo" requires the extension "random". Enable it or install
367
   a polyfill.
368
369
370
EOF
371
            ];
372
        })();
373
    }
374
}
375