Skip to content

Commit e5a152c

Browse files
authored
fix: Fix the compatibility of the dumped autoload (#891)
The dumped autoload should remain compatible with PHP 7.2.
1 parent 83a0211 commit e5a152c

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

.makefile/e2e.file

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ _e2e_038:
408408
e2e_039: # Runs end-to-end tests for the fixture set e2e_037 — Codebase using scoped code
409409
e2e_039: $(PHP_SCOPER_PHAR_BIN)
410410
rm -rf fixtures/set039-min-php-version/vendor || true
411+
docker pull php:7.2-cli-alpine
411412

412413
composer --working-dir=fixtures/set039-min-php-version install
413414

@@ -427,7 +428,7 @@ e2e_039: $(PHP_SCOPER_PHAR_BIN)
427428
--volume="$$PWD":/opt/php-scoper \
428429
php:7.2-cli-alpine \
429430
php build/set039/index.php \
430-
> build/set039/output
431+
> build/set039/output || true
431432
diff fixtures/set039-min-php-version/expected-output build/set039/output
432433

433434

src/Autoload/ScoperAutoloadGenerator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ public function dump(): string
111111
if (file_exists(\$installedVersionsPath)) require_once \$installedVersionsPath;
112112
113113
// Restore the backup and ensure the excluded files are properly marked as loaded
114-
\$GLOBALS['__composer_autoload_files'] = [
115-
...\$existingComposerAutoloadFiles,
116-
...array_fill_keys({$excludedComposerAutoloadFiles}, true),
117-
];
114+
\$GLOBALS['__composer_autoload_files'] = \\array_merge(
115+
\$existingComposerAutoloadFiles,
116+
\\array_fill_keys({$excludedComposerAutoloadFiles}, true)
117+
);
118118
119119
return \$loader;
120120
})();
@@ -143,10 +143,10 @@ public function dump(): string
143143
if (file_exists(\$installedVersionsPath)) require_once \$installedVersionsPath;
144144
145145
// Restore the backup and ensure the excluded files are properly marked as loaded
146-
\$GLOBALS['__composer_autoload_files'] = [
147-
...\$existingComposerAutoloadFiles,
148-
...array_fill_keys({$excludedComposerAutoloadFiles}, true),
149-
];
146+
\$GLOBALS['__composer_autoload_files'] = \\array_merge(
147+
\$existingComposerAutoloadFiles,
148+
\\array_fill_keys({$excludedComposerAutoloadFiles}, true)
149+
);
150150
151151
return \$loader;
152152
})();

tests/Autoload/AutoloadDumperTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public static function autoloadProvider(): iterable
185185
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
186186
187187
// Restore the backup and ensure the excluded files are properly marked as loaded
188-
$GLOBALS['__composer_autoload_files'] = [
189-
...$existingComposerAutoloadFiles,
190-
...array_fill_keys([], true),
191-
];
188+
$GLOBALS['__composer_autoload_files'] = \array_merge(
189+
$existingComposerAutoloadFiles,
190+
\array_fill_keys([], true)
191+
);
192192
193193
return $loader;
194194
})();
@@ -282,10 +282,10 @@ public static function autoloadProvider(): iterable
282282
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
283283
284284
// Restore the backup and ensure the excluded files are properly marked as loaded
285-
$GLOBALS['__composer_autoload_files'] = [
286-
...$existingComposerAutoloadFiles,
287-
...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true),
288-
];
285+
$GLOBALS['__composer_autoload_files'] = \array_merge(
286+
$existingComposerAutoloadFiles,
287+
\array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true)
288+
);
289289
290290
return $loader;
291291
})();
@@ -381,10 +381,10 @@ public static function autoloadProvider(): iterable
381381
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
382382
383383
// Restore the backup and ensure the excluded files are properly marked as loaded
384-
$GLOBALS['__composer_autoload_files'] = [
385-
...$existingComposerAutoloadFiles,
386-
...array_fill_keys([], true),
387-
];
384+
$GLOBALS['__composer_autoload_files'] = \array_merge(
385+
$existingComposerAutoloadFiles,
386+
\array_fill_keys([], true)
387+
);
388388
389389
return $loader;
390390
})();

tests/Autoload/ScoperAutoloadGeneratorTest.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public static function provideRegistry(): iterable
5858
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
5959
6060
// Restore the backup and ensure the excluded files are properly marked as loaded
61-
$GLOBALS['__composer_autoload_files'] = [
62-
...$existingComposerAutoloadFiles,
63-
...array_fill_keys([], true),
64-
];
61+
$GLOBALS['__composer_autoload_files'] = \array_merge(
62+
$existingComposerAutoloadFiles,
63+
\array_fill_keys([], true)
64+
);
6565
6666
return $loader;
6767
})();
@@ -89,10 +89,10 @@ public static function provideRegistry(): iterable
8989
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
9090
9191
// Restore the backup and ensure the excluded files are properly marked as loaded
92-
$GLOBALS['__composer_autoload_files'] = [
93-
...$existingComposerAutoloadFiles,
94-
...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true),
95-
];
92+
$GLOBALS['__composer_autoload_files'] = \array_merge(
93+
$existingComposerAutoloadFiles,
94+
\array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true)
95+
);
9696
9797
return $loader;
9898
})();
@@ -126,10 +126,10 @@ public static function provideRegistry(): iterable
126126
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
127127
128128
// Restore the backup and ensure the excluded files are properly marked as loaded
129-
$GLOBALS['__composer_autoload_files'] = [
130-
...$existingComposerAutoloadFiles,
131-
...array_fill_keys([], true),
132-
];
129+
$GLOBALS['__composer_autoload_files'] = \array_merge(
130+
$existingComposerAutoloadFiles,
131+
\array_fill_keys([], true)
132+
);
133133
134134
return $loader;
135135
})();
@@ -168,10 +168,10 @@ public static function provideRegistry(): iterable
168168
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
169169
170170
// Restore the backup and ensure the excluded files are properly marked as loaded
171-
$GLOBALS['__composer_autoload_files'] = [
172-
...$existingComposerAutoloadFiles,
173-
...array_fill_keys([], true),
174-
];
171+
$GLOBALS['__composer_autoload_files'] = \array_merge(
172+
$existingComposerAutoloadFiles,
173+
\array_fill_keys([], true)
174+
);
175175
176176
return $loader;
177177
})();
@@ -212,10 +212,10 @@ public static function provideRegistry(): iterable
212212
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
213213
214214
// Restore the backup and ensure the excluded files are properly marked as loaded
215-
$GLOBALS['__composer_autoload_files'] = [
216-
...$existingComposerAutoloadFiles,
217-
...array_fill_keys([], true),
218-
];
215+
$GLOBALS['__composer_autoload_files'] = \array_merge(
216+
$existingComposerAutoloadFiles,
217+
\array_fill_keys([], true)
218+
);
219219
220220
return $loader;
221221
})();
@@ -265,10 +265,10 @@ public static function provideRegistry(): iterable
265265
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
266266
267267
// Restore the backup and ensure the excluded files are properly marked as loaded
268-
$GLOBALS['__composer_autoload_files'] = [
269-
...$existingComposerAutoloadFiles,
270-
...array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true),
271-
];
268+
$GLOBALS['__composer_autoload_files'] = \array_merge(
269+
$existingComposerAutoloadFiles,
270+
\array_fill_keys(['a610a8e036135f992c6edfb10ca9f4e9', 'e252736c6babb7c097ab6692dbcb2a5a'], true)
271+
);
272272
273273
return $loader;
274274
})();
@@ -318,10 +318,10 @@ public static function provideRegistry(): iterable
318318
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
319319
320320
// Restore the backup and ensure the excluded files are properly marked as loaded
321-
$GLOBALS['__composer_autoload_files'] = [
322-
...$existingComposerAutoloadFiles,
323-
...array_fill_keys([], true),
324-
];
321+
$GLOBALS['__composer_autoload_files'] = \array_merge(
322+
$existingComposerAutoloadFiles,
323+
\array_fill_keys([], true)
324+
);
325325
326326
return $loader;
327327
})();
@@ -368,10 +368,10 @@ public static function provideRegistry(): iterable
368368
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
369369
370370
// Restore the backup and ensure the excluded files are properly marked as loaded
371-
$GLOBALS['__composer_autoload_files'] = [
372-
...$existingComposerAutoloadFiles,
373-
...array_fill_keys([], true),
374-
];
371+
$GLOBALS['__composer_autoload_files'] = \array_merge(
372+
$existingComposerAutoloadFiles,
373+
\array_fill_keys([], true)
374+
);
375375
376376
return $loader;
377377
})();
@@ -416,10 +416,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) {
416416
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
417417
418418
// Restore the backup and ensure the excluded files are properly marked as loaded
419-
$GLOBALS['__composer_autoload_files'] = [
420-
...$existingComposerAutoloadFiles,
421-
...array_fill_keys([], true),
422-
];
419+
$GLOBALS['__composer_autoload_files'] = \array_merge(
420+
$existingComposerAutoloadFiles,
421+
\array_fill_keys([], true)
422+
);
423423
424424
return $loader;
425425
})();
@@ -471,10 +471,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) {
471471
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
472472
473473
// Restore the backup and ensure the excluded files are properly marked as loaded
474-
$GLOBALS['__composer_autoload_files'] = [
475-
...$existingComposerAutoloadFiles,
476-
...array_fill_keys([], true),
477-
];
474+
$GLOBALS['__composer_autoload_files'] = \array_merge(
475+
$existingComposerAutoloadFiles,
476+
\array_fill_keys([], true)
477+
);
478478
479479
return $loader;
480480
})();
@@ -540,10 +540,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) {
540540
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
541541
542542
// Restore the backup and ensure the excluded files are properly marked as loaded
543-
$GLOBALS['__composer_autoload_files'] = [
544-
...$existingComposerAutoloadFiles,
545-
...array_fill_keys([], true),
546-
];
543+
$GLOBALS['__composer_autoload_files'] = \array_merge(
544+
$existingComposerAutoloadFiles,
545+
\array_fill_keys([], true)
546+
);
547547
548548
return $loader;
549549
})();
@@ -583,10 +583,10 @@ function humbug_phpscoper_expose_class($exposed, $prefixed) {
583583
if (file_exists($installedVersionsPath)) require_once $installedVersionsPath;
584584
585585
// Restore the backup and ensure the excluded files are properly marked as loaded
586-
$GLOBALS['__composer_autoload_files'] = [
587-
...$existingComposerAutoloadFiles,
588-
...array_fill_keys([], true),
589-
];
586+
$GLOBALS['__composer_autoload_files'] = \array_merge(
587+
$existingComposerAutoloadFiles,
588+
\array_fill_keys([], true)
589+
);
590590
591591
return $loader;
592592
})();

0 commit comments

Comments
 (0)