From e5a152c0f40c6cf7994fb27f14e50e47d7c4c4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:43:20 +0100 Subject: [PATCH] fix: Fix the compatibility of the dumped autoload (#891) The dumped autoload should remain compatible with PHP 7.2. --- .makefile/e2e.file | 3 +- src/Autoload/ScoperAutoloadGenerator.php | 16 ++-- tests/Autoload/AutoloadDumperTest.php | 24 ++--- .../Autoload/ScoperAutoloadGeneratorTest.php | 96 +++++++++---------- 4 files changed, 70 insertions(+), 69 deletions(-) diff --git a/.makefile/e2e.file b/.makefile/e2e.file index 1f2527c8..26e871af 100644 --- a/.makefile/e2e.file +++ b/.makefile/e2e.file @@ -408,6 +408,7 @@ _e2e_038: e2e_039: # Runs end-to-end tests for the fixture set e2e_037 — Codebase using scoped code e2e_039: $(PHP_SCOPER_PHAR_BIN) rm -rf fixtures/set039-min-php-version/vendor || true + docker pull php:7.2-cli-alpine composer --working-dir=fixtures/set039-min-php-version install @@ -427,7 +428,7 @@ e2e_039: $(PHP_SCOPER_PHAR_BIN) --volume="$$PWD":/opt/php-scoper \ php:7.2-cli-alpine \ php build/set039/index.php \ - > build/set039/output + > build/set039/output || true diff fixtures/set039-min-php-version/expected-output build/set039/output diff --git a/src/Autoload/ScoperAutoloadGenerator.php b/src/Autoload/ScoperAutoloadGenerator.php index c5258115..0dc62b10 100644 --- a/src/Autoload/ScoperAutoloadGenerator.php +++ b/src/Autoload/ScoperAutoloadGenerator.php @@ -111,10 +111,10 @@ public function dump(): string if (file_exists(\$installedVersionsPath)) require_once \$installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - \$GLOBALS['__composer_autoload_files'] = [ - ...\$existingComposerAutoloadFiles, - ...array_fill_keys({$excludedComposerAutoloadFiles}, true), - ]; + \$GLOBALS['__composer_autoload_files'] = \\array_merge( + \$existingComposerAutoloadFiles, + \\array_fill_keys({$excludedComposerAutoloadFiles}, true) + ); return \$loader; })(); @@ -143,10 +143,10 @@ public function dump(): string if (file_exists(\$installedVersionsPath)) require_once \$installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - \$GLOBALS['__composer_autoload_files'] = [ - ...\$existingComposerAutoloadFiles, - ...array_fill_keys({$excludedComposerAutoloadFiles}, true), - ]; + \$GLOBALS['__composer_autoload_files'] = \\array_merge( + \$existingComposerAutoloadFiles, + \\array_fill_keys({$excludedComposerAutoloadFiles}, true) + ); return \$loader; })(); diff --git a/tests/Autoload/AutoloadDumperTest.php b/tests/Autoload/AutoloadDumperTest.php index 7f156877..9df461dc 100644 --- a/tests/Autoload/AutoloadDumperTest.php +++ b/tests/Autoload/AutoloadDumperTest.php @@ -185,10 +185,10 @@ public static function autoloadProvider(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -282,10 +282,10 @@ public static function autoloadProvider(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true) + ); return $loader; })(); @@ -381,10 +381,10 @@ public static function autoloadProvider(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); diff --git a/tests/Autoload/ScoperAutoloadGeneratorTest.php b/tests/Autoload/ScoperAutoloadGeneratorTest.php index 8d7404f1..efad5517 100644 --- a/tests/Autoload/ScoperAutoloadGeneratorTest.php +++ b/tests/Autoload/ScoperAutoloadGeneratorTest.php @@ -58,10 +58,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -89,10 +89,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true) + ); return $loader; })(); @@ -126,10 +126,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -168,10 +168,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -212,10 +212,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -265,10 +265,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true) + ); return $loader; })(); @@ -318,10 +318,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -368,10 +368,10 @@ public static function provideRegistry(): iterable if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -416,10 +416,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) { if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -471,10 +471,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) { if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -540,10 +540,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) { if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })(); @@ -583,10 +583,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) { if (file_exists($installedVersionsPath)) require_once $installedVersionsPath; // Restore the backup and ensure the excluded files are properly marked as loaded - $GLOBALS['__composer_autoload_files'] = [ - ...$existingComposerAutoloadFiles, - ...array_fill_keys([], true), - ]; + $GLOBALS['__composer_autoload_files'] = \array_merge( + $existingComposerAutoloadFiles, + \array_fill_keys([], true) + ); return $loader; })();