Issues (224)

tests/AutoReview/MakefileTest.php (1 issue)

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
            Usage:
38
              make TARGET
39
            
40
            #
41
            # Commands
42
            #---------------------------------------------------------------------------
43
            
44
            check:	 	 Runs all checks
45
            clean: 	 	 Cleans all created artifacts
46
            dump:	 	 Dumps the requirement-checker
47
            autoreview:	 AutoReview checks
48
            cs:	 	 Fixes CS
49
            cs_lint: 	 Checks CS
50
            test:		 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
The expression return array_values(arra...on(...) { /* ... */ })) returns the type array which is incompatible with the documented return type Fidry\Makefile\Rule.
Loading history...
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