|
14 | 14 |
|
15 | 15 | namespace Humbug\PhpScoper\AutoReview; |
16 | 16 |
|
17 | | -use PHPUnit\Framework\TestCase; |
| 17 | +use Fidry\Makefile\Rule; |
| 18 | +use Fidry\Makefile\Test\BaseMakefileTestCase; |
18 | 19 | use function array_filter; |
19 | 20 | use function array_map; |
20 | | -use function array_unique; |
21 | 21 | use function array_values; |
22 | | -use function explode; |
23 | | -use function Safe\file_get_contents; |
24 | | -use function Safe\preg_match; |
25 | | -use function Safe\preg_match_all; |
| 22 | +use function current; |
| 23 | +use function str_starts_with; |
26 | 24 |
|
27 | 25 | /** |
28 | 26 | * @coversNothing |
29 | 27 | * |
30 | 28 | * @internal |
31 | 29 | */ |
32 | | -class MakefileE2ETest extends TestCase |
| 30 | +class MakefileE2ETest extends BaseMakefileTestCase |
33 | 31 | { |
34 | | - private const MAKEFILE_PATH = __DIR__.'/../../Makefile'; |
35 | | - |
36 | | - private static string $makeFileContents; |
| 32 | + protected static function getMakefilePath(): string |
| 33 | + { |
| 34 | + return __DIR__.'/../../Makefile'; |
| 35 | + } |
37 | 36 |
|
38 | | - public static function setUpBeforeClass(): void |
| 37 | + protected function getExpectedHelpOutput(): string |
39 | 38 | { |
40 | | - self::$makeFileContents = file_get_contents(self::MAKEFILE_PATH); |
| 39 | + return <<<'EOF' |
| 40 | + [33mUsage:[0m |
| 41 | + make TARGET |
| 42 | +
|
| 43 | + [32m# |
| 44 | + # Commands |
| 45 | + #---------------------------------------------------------------------------[0m |
| 46 | +
|
| 47 | + [33mcheck:[0m Runs all checks |
| 48 | + [33mclean:[0m Cleans all created artifacts |
| 49 | + [33mupdate_root_version:[0m Checks the latest GitHub release and update COMPOSER_ROOT_VERSION accordingly |
| 50 | + [33mcs:[0m Fixes CS |
| 51 | + [33mcs_lint:[0m Checks CS |
| 52 | + [33mphpstan:[0m Runs PHPStan |
| 53 | + [33mbuild:[0m Builds the PHAR |
| 54 | + [33moutdated_fixtures:[0m Reports outdated dependencies |
| 55 | + [33mtest:[0m Runs all the tests |
| 56 | + [33mvalidate_package:[0m Validates the composer.json |
| 57 | + [33mcheck_composer_root_version:[0m Checks that the COMPOSER_ROOT_VERSION is up to date |
| 58 | + [33mcovers_validator:[0m Checks PHPUnit @coves tag |
| 59 | + [33mphpunit:[0m Runs PHPUnit tests |
| 60 | + [33mphpunit_coverage_infection:[0m Runs PHPUnit tests with test coverage |
| 61 | + [33mphpunit_coverage_html:[0m Runs PHPUnit with code coverage with HTML report |
| 62 | + [33minfection:[0m Runs Infection |
| 63 | + [33mblackfire:[0m Runs Blackfire profiling |
| 64 | + [33me2e:[0m Runs end-to-end tests |
| 65 | + [33me2e_004:[0m Runs end-to-end tests for the fixture set 004 — Minimalistic codebase |
| 66 | + [33me2e_005:[0m Runs end-to-end tests for the fixture set 005 — Codebase with third-party code |
| 67 | + [33me2e_011:[0m Runs end-to-end tests for the fixture set 011 — Codebase with exposed symbols |
| 68 | + [33me2e_013:[0m Runs end-to-end tests for the fixture set 013 — Test the init command |
| 69 | + [33me2e_014:[0m Runs end-to-end tests for the fixture set 014 — Codebase with PSR-0 autoloading |
| 70 | + [33me2e_015:[0m Runs end-to-end tests for the fixture set 015 — Codebase with third-party code using PSR-0 autoloading |
| 71 | + [33me2e_016:[0m Runs end-to-end tests for the fixture set 016 — Scoping of the Symfony Finder component |
| 72 | + [33me2e_017:[0m Runs end-to-end tests for the fixture set 017 — Scoping of the Symfony DependencyInjection component |
| 73 | + [33me2e_018:[0m Runs end-to-end tests for the fixture set 018 — Scoping of nikic/php-parser |
| 74 | + [33me2e_019:[0m Runs end-to-end tests for the fixture set 019 — Scoping of the Symfony Console component |
| 75 | + [33me2e_020:[0m Runs end-to-end tests for the fixture set 020 — Scoping of Infection |
| 76 | + [33me2e_024:[0m Runs end-to-end tests for the fixture set 024 — Scoping of a codebase with global functions exposed |
| 77 | + [33me2e_025:[0m Runs end-to-end tests for the fixture set 025 — Scoping of a codebase using third-party exposed functions |
| 78 | + [33me2e_027:[0m Runs end-to-end tests for the fixture set 027 — Scoping of a Laravel |
| 79 | + [33me2e_028:[0m Runs end-to-end tests for the fixture set 028 — Scoping of a Symfony project |
| 80 | + [33me2e_029:[0m Runs end-to-end tests for the fixture set 029 — Scoping of the EasyRdf project |
| 81 | + [33me2e_030:[0m Runs end-to-end tests for the fixture set 030 — Scoping of a codebase with globally registered functions |
| 82 | + [33me2e_031:[0m Runs end-to-end tests for the fixture set 031 — Scoping of a codebase using symbols of a non-loaded PHP extension |
| 83 | + [33me2e_032:[0m Runs end-to-end tests for the fixture set 032 — Scoping of a codebase using the isolated finder in the configuration |
| 84 | + [33me2e_033:[0m Runs end-to-end tests for the fixture set 033 — Scoping of a codebase a function registered in the global namespace |
| 85 | + [33me2e_034:[0m Runs end-to-end tests for the fixture set 034 — Leverage Composer InstalledVersions |
| 86 | + [33me2e_035:[0m Runs end-to-end tests for the fixture set 035 — Tests tha composer autoloaded files are working fine |
| 87 | + |
| 88 | + EOF; |
41 | 89 | } |
42 | 90 |
|
43 | 91 | public function test_the_e2e_test_executes_all_the_e2e_sub_rules(): void |
44 | 92 | { |
45 | | - $mainE2ERule = self::retrieveE2ERule(self::$makeFileContents); |
46 | | - $e2eSubRules = self::retrieveSubE2ERules(self::$makeFileContents); |
| 93 | + $mainE2ERule = self::retrieveE2ERule(); |
| 94 | + $e2eSubRules = self::retrieveSubE2ERules(); |
47 | 95 |
|
48 | 96 | self::assertSame($e2eSubRules, $mainE2ERule); |
49 | 97 | } |
50 | 98 |
|
51 | 99 | public function test_it_lists_all_e2e_tests(): void |
52 | 100 | { |
53 | 101 | $expected = E2ECollector::getE2ENames(); |
54 | | - $actual = self::retrieveE2ERule(self::$makeFileContents); |
| 102 | + $actual = self::retrieveE2ERule(); |
55 | 103 |
|
56 | 104 | self::assertEqualsCanonicalizing($expected, $actual); |
57 | 105 | } |
58 | 106 |
|
59 | 107 | /** |
60 | 108 | * @return list<string> |
61 | 109 | */ |
62 | | - private static function retrieveE2ERule(string $makefileContents): array |
| 110 | + private static function retrieveE2ERule(): array |
63 | 111 | { |
64 | | - if (1 !== preg_match( |
65 | | - '/e2e:(?<steps>[\p{L}\d_ ]+)/u', |
66 | | - $makefileContents, |
67 | | - $matches, |
68 | | - )) { |
69 | | - self::assertFalse(false, 'Expected the string input to match the regex'); |
70 | | - } |
71 | | - |
72 | | - return array_values( |
73 | | - array_filter( |
74 | | - array_map( |
75 | | - 'trim', |
76 | | - explode( |
77 | | - ' ', |
78 | | - $matches['steps'], |
79 | | - ), |
80 | | - ), |
81 | | - ), |
| 112 | + $e2eRules = array_filter( |
| 113 | + self::getParsedRules(), |
| 114 | + static fn (Rule $rule) => $rule->getTarget() === 'e2e' && !$rule->isComment(), |
82 | 115 | ); |
| 116 | + |
| 117 | + $e2eRule = current($e2eRules); |
| 118 | + self::assertNotFalse($e2eRule, 'Expected to find the e2e rule in the Makefile.'); |
| 119 | + |
| 120 | + return $e2eRule->getPrerequisites(); |
83 | 121 | } |
84 | 122 |
|
85 | 123 | /** |
86 | 124 | * @return list<string> |
87 | 125 | */ |
88 | | - private static function retrieveSubE2ERules(string $makefileContents): array |
| 126 | + private static function retrieveSubE2ERules(): array |
89 | 127 | { |
90 | | - if (1 !== preg_match_all( |
91 | | - '/(?<step>e2e_\d+):/u', |
92 | | - $makefileContents, |
93 | | - $matches, |
94 | | - )) { |
95 | | - self::assertFalse(false, 'Expected the string input to match the regex'); |
96 | | - } |
| 128 | + $e2eRules = array_filter( |
| 129 | + self::getParsedRules(), |
| 130 | + static fn (Rule $rule) => str_starts_with($rule->getTarget(), 'e2e_') && !$rule->isComment(), |
| 131 | + ); |
97 | 132 |
|
98 | 133 | return array_values( |
99 | | - array_unique( |
100 | | - array_filter( |
101 | | - array_map( |
102 | | - 'trim', |
103 | | - $matches['step'], |
104 | | - ), |
105 | | - ), |
| 134 | + array_map( |
| 135 | + static fn (Rule $rule) => $rule->getTarget(), |
| 136 | + $e2eRules, |
106 | 137 | ), |
107 | 138 | ); |
108 | 139 | } |
|
0 commit comments