Skip to content

Commit

Permalink
fix: Fix the compatibility of the dumped autoload (#891)
Browse files Browse the repository at this point in the history
The dumped autoload should remain compatible with PHP 7.2.
  • Loading branch information
theofidry authored Nov 4, 2023
1 parent 83a0211 commit e5a152c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .makefile/e2e.file
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down
16 changes: 8 additions & 8 deletions src/Autoload/ScoperAutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down
24 changes: 12 additions & 12 deletions tests/Autoload/AutoloadDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down
96 changes: 48 additions & 48 deletions tests/Autoload/ScoperAutoloadGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down Expand Up @@ -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;
})();
Expand Down

0 comments on commit e5a152c

Please sign in to comment.