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\AutoReview; |
||
16 | |||
17 | use Fidry\Makefile\Rule; |
||
18 | use Fidry\Makefile\Test\BaseMakefileTestCase; |
||
19 | use PHPUnit\Framework\Attributes\CoversNothing; |
||
20 | |||
21 | /** |
||
22 | * @internal |
||
23 | */ |
||
24 | #[CoversNothing] |
||
25 | final class MakefileTest extends BaseMakefileTestCase |
||
26 | { |
||
27 | public const MAKEFILE_PATH = __DIR__.'/../../Makefile'; |
||
28 | |||
29 | protected static function getMakefilePath(): string |
||
30 | { |
||
31 | return self::MAKEFILE_PATH; |
||
32 | } |
||
33 | |||
34 | protected function getExpectedHelpOutput(): string |
||
35 | { |
||
36 | return <<<'EOF' |
||
37 | [33mUsage:[0m |
||
38 | make TARGET |
||
39 | |||
40 | [32m# |
||
41 | # Commands |
||
42 | #---------------------------------------------------------------------------[0m |
||
43 | |||
44 | [33mcheck:[0m Runs all checks |
||
45 | [33mclean:[0m Cleans all created artifacts |
||
46 | [33mdump:[0m Dumps the requirement-checker |
||
47 | [33mautoreview:[0m AutoReview checks |
||
48 | [33mcs:[0m Fixes CS |
||
49 | [33mcs_lint:[0m Checks CS |
||
50 | [33mtest:[0m Runs all the tests |
||
51 | |||
52 | EOF; |
||
53 | } |
||
54 | |||
55 | public function test_the_test_rule_contains_all_test_targets(): void |
||
56 | { |
||
57 | $testRule = self::getTestRule(); |
||
58 | $testTargets = self::getTestRules(); |
||
59 | |||
60 | // Sanity check |
||
61 | self::assertGreaterThan(0, count($testRule->getPrerequisites())); |
||
62 | |||
63 | self::assertEqualsCanonicalizing( |
||
64 | $testRule->getPrerequisites(), |
||
65 | array_map( |
||
66 | static fn (Rule $rule) => $rule->getTarget(), |
||
67 | $testTargets, |
||
68 | ), |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | private static function getTestRule(): Rule |
||
73 | { |
||
74 | return current( |
||
75 | array_filter( |
||
76 | self::getParsedRules(), |
||
77 | static fn (Rule $rule) => 'test' === $rule->getTarget() && !$rule->isComment() && !$rule->isPhony(), |
||
78 | ), |
||
79 | ); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return Rule |
||
84 | */ |
||
85 | private static function getTestRules(): array |
||
86 | { |
||
87 | return array_values( |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
88 | array_filter( |
||
89 | self::getParsedRules(), |
||
90 | static fn (Rule $rule) => str_starts_with($rule->getTarget(), 'test_') && !$rule->isComment() && !$rule->isPhony(), |
||
91 | ), |
||
92 | ); |
||
93 | } |
||
94 | } |
||
95 |