Skip to content

Commit 25143ea

Browse files
authored
refactor: Rework the makefile test with FidryMakefile (#792)
1 parent 71f95ee commit 25143ea

File tree

4 files changed

+152
-55
lines changed

4 files changed

+152
-55
lines changed

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ e2e_025: $(PHP_SCOPER_PHAR_BIN) fixtures/set025/vendor
342342

343343
.PHONY: e2e_027
344344
e2e_027: ## Runs end-to-end tests for the fixture set 027 — Scoping of a Laravel
345-
ifeq ("$(IS_PHP8)", "true")
346345
e2e_027: $(PHP_SCOPER_PHAR_BIN) fixtures/set027-laravel/vendor
347346
$(PHP_SCOPER_PHAR) add-prefix \
348347
--working-dir=fixtures/set027-laravel \
@@ -354,10 +353,6 @@ e2e_027: $(PHP_SCOPER_PHAR_BIN) fixtures/set027-laravel/vendor
354353

355354
php build/set027-laravel/artisan -V > build/set027-laravel/output
356355
diff fixtures/set027-laravel/expected-output build/set027-laravel/output
357-
else
358-
e2e_027:
359-
echo "SKIP e2e_027: PHP version not supported"
360-
endif
361356

362357
.PHONY: e2e_028
363358
e2e_028: ## Runs end-to-end tests for the fixture set 028 — Scoping of a Symfony project

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"require-dev": {
3131
"bamarni/composer-bin-plugin": "^1.1",
3232
"ergebnis/composer-normalize": "^2.28",
33+
"fidry/makefile": "^0.2.1",
3334
"humbug/box": "^4.0",
3435
"phpspec/prophecy-phpunit": "^2.0",
3536
"phpunit/phpunit": "^9.0",

composer.lock

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/AutoReview/MakefileE2ETest.php

Lines changed: 80 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,95 +14,126 @@
1414

1515
namespace Humbug\PhpScoper\AutoReview;
1616

17-
use PHPUnit\Framework\TestCase;
17+
use Fidry\Makefile\Rule;
18+
use Fidry\Makefile\Test\BaseMakefileTestCase;
1819
use function array_filter;
1920
use function array_map;
20-
use function array_unique;
2121
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;
2624

2725
/**
2826
* @coversNothing
2927
*
3028
* @internal
3129
*/
32-
class MakefileE2ETest extends TestCase
30+
class MakefileE2ETest extends BaseMakefileTestCase
3331
{
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+
}
3736

38-
public static function setUpBeforeClass(): void
37+
protected function getExpectedHelpOutput(): string
3938
{
40-
self::$makeFileContents = file_get_contents(self::MAKEFILE_PATH);
39+
return <<<'EOF'
40+
Usage:
41+
make TARGET
42+
43+
#
44+
# Commands
45+
#---------------------------------------------------------------------------
46+
47+
check: Runs all checks
48+
clean: Cleans all created artifacts
49+
update_root_version: Checks the latest GitHub release and update COMPOSER_ROOT_VERSION accordingly
50+
cs: Fixes CS
51+
cs_lint: Checks CS
52+
phpstan: Runs PHPStan
53+
build: Builds the PHAR
54+
outdated_fixtures: Reports outdated dependencies
55+
test: Runs all the tests
56+
validate_package: Validates the composer.json
57+
check_composer_root_version: Checks that the COMPOSER_ROOT_VERSION is up to date
58+
covers_validator: Checks PHPUnit @coves tag
59+
phpunit: Runs PHPUnit tests
60+
phpunit_coverage_infection: Runs PHPUnit tests with test coverage
61+
phpunit_coverage_html: Runs PHPUnit with code coverage with HTML report
62+
infection: Runs Infection
63+
blackfire: Runs Blackfire profiling
64+
e2e: Runs end-to-end tests
65+
e2e_004: Runs end-to-end tests for the fixture set 004 — Minimalistic codebase
66+
e2e_005: Runs end-to-end tests for the fixture set 005 — Codebase with third-party code
67+
e2e_011: Runs end-to-end tests for the fixture set 011 — Codebase with exposed symbols
68+
e2e_013: Runs end-to-end tests for the fixture set 013 — Test the init command
69+
e2e_014: Runs end-to-end tests for the fixture set 014 — Codebase with PSR-0 autoloading
70+
e2e_015: Runs end-to-end tests for the fixture set 015 — Codebase with third-party code using PSR-0 autoloading
71+
e2e_016: Runs end-to-end tests for the fixture set 016 — Scoping of the Symfony Finder component
72+
e2e_017: Runs end-to-end tests for the fixture set 017 — Scoping of the Symfony DependencyInjection component
73+
e2e_018: Runs end-to-end tests for the fixture set 018 — Scoping of nikic/php-parser
74+
e2e_019: Runs end-to-end tests for the fixture set 019 — Scoping of the Symfony Console component
75+
e2e_020: Runs end-to-end tests for the fixture set 020 — Scoping of Infection
76+
e2e_024: Runs end-to-end tests for the fixture set 024 — Scoping of a codebase with global functions exposed
77+
e2e_025: Runs end-to-end tests for the fixture set 025 — Scoping of a codebase using third-party exposed functions
78+
e2e_027: Runs end-to-end tests for the fixture set 027 — Scoping of a Laravel
79+
e2e_028: Runs end-to-end tests for the fixture set 028 — Scoping of a Symfony project
80+
e2e_029: Runs end-to-end tests for the fixture set 029 — Scoping of the EasyRdf project
81+
e2e_030: Runs end-to-end tests for the fixture set 030 — Scoping of a codebase with globally registered functions
82+
e2e_031: Runs end-to-end tests for the fixture set 031 — Scoping of a codebase using symbols of a non-loaded PHP extension
83+
e2e_032: Runs end-to-end tests for the fixture set 032 — Scoping of a codebase using the isolated finder in the configuration
84+
e2e_033: Runs end-to-end tests for the fixture set 033 — Scoping of a codebase a function registered in the global namespace
85+
e2e_034: Runs end-to-end tests for the fixture set 034 — Leverage Composer InstalledVersions
86+
e2e_035: Runs end-to-end tests for the fixture set 035 — Tests tha composer autoloaded files are working fine
87+
88+
EOF;
4189
}
4290

4391
public function test_the_e2e_test_executes_all_the_e2e_sub_rules(): void
4492
{
45-
$mainE2ERule = self::retrieveE2ERule(self::$makeFileContents);
46-
$e2eSubRules = self::retrieveSubE2ERules(self::$makeFileContents);
93+
$mainE2ERule = self::retrieveE2ERule();
94+
$e2eSubRules = self::retrieveSubE2ERules();
4795

4896
self::assertSame($e2eSubRules, $mainE2ERule);
4997
}
5098

5199
public function test_it_lists_all_e2e_tests(): void
52100
{
53101
$expected = E2ECollector::getE2ENames();
54-
$actual = self::retrieveE2ERule(self::$makeFileContents);
102+
$actual = self::retrieveE2ERule();
55103

56104
self::assertEqualsCanonicalizing($expected, $actual);
57105
}
58106

59107
/**
60108
* @return list<string>
61109
*/
62-
private static function retrieveE2ERule(string $makefileContents): array
110+
private static function retrieveE2ERule(): array
63111
{
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(),
82115
);
116+
117+
$e2eRule = current($e2eRules);
118+
self::assertNotFalse($e2eRule, 'Expected to find the e2e rule in the Makefile.');
119+
120+
return $e2eRule->getPrerequisites();
83121
}
84122

85123
/**
86124
* @return list<string>
87125
*/
88-
private static function retrieveSubE2ERules(string $makefileContents): array
126+
private static function retrieveSubE2ERules(): array
89127
{
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+
);
97132

98133
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,
106137
),
107138
);
108139
}

0 commit comments

Comments
 (0)