-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Correct the Composer autoload (#864)
In [0.18.0-rc.0](https://github.com/humbug/php-scoper/releases/tag/0.18.0-rc.0), more specifically in #298, the composer autoload global variable is completely reset. This is actually a problem for when there is excluded files, as they now count as not loaded and if included again in another project, will be loaded, which can cause problems.
- Loading branch information
Showing
48 changed files
with
4,226 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,7 +314,10 @@ e2e_034: $(PHP_SCOPER_PHAR_BIN) fixtures/set034-installed-versions/vendor | |
|
||
.PHONY: e2e_035 | ||
e2e_035: # Runs end-to-end tests for the fixture set 035 — Tests tha composer autoloaded files are working fine | ||
e2e_035: $(PHP_SCOPER_PHAR_BIN) fixtures/set035-composer-files-autoload/vendor fixtures/set035-composer-files-autoload/guzzle5-include/vendor | ||
e2e_035: $(PHP_SCOPER_PHAR_BIN) \ | ||
fixtures/set035-composer-files-autoload/vendor \ | ||
fixtures/set035-composer-files-autoload/guzzle5-include/vendor \ | ||
fixtures/set035-composer-files-autoload/composer-variable-access/vendor | ||
rm -rf build/set035-composer-files-autoload || true | ||
cp -R fixtures/set035-composer-files-autoload build/set035-composer-files-autoload | ||
|
||
|
@@ -328,6 +331,16 @@ e2e_035: $(PHP_SCOPER_PHAR_BIN) fixtures/set035-composer-files-autoload/vendor f | |
composer --working-dir=build/set035-composer-files-autoload/scoped-guzzle5-include dump-autoload | ||
rm -rf build/set035-composer-files-autoload/guzzle5-include || true | ||
|
||
$(PHP_SCOPER_PHAR) add-prefix \ | ||
--working-dir=fixtures/set035-composer-files-autoload/composer-variable-access \ | ||
--output-dir=../../../build/set035-composer-files-autoload/scoped-composer-variable-access \ | ||
--force \ | ||
--config=scoper.inc.php \ | ||
--no-interaction \ | ||
--stop-on-failure | ||
composer --working-dir=build/set035-composer-files-autoload/scoped-composer-variable-access dump-autoload | ||
rm -rf build/set035-composer-files-autoload/composer-variable-access || true | ||
|
||
php build/set035-composer-files-autoload/index.php 2>&1 > build/set035-composer-files-autoload/output | ||
php build/set035-composer-files-autoload/test.php | ||
|
||
|
@@ -530,6 +543,13 @@ fixtures/set035-composer-files-autoload/guzzle5-include/composer.lock: fixtures/ | |
@echo "$(@) is not up to date. You may want to run the following command:" | ||
@echo "$$ composer --working-dir=fixtures/set035-composer-files-autoload/guzzle5-include update --lock && touch -c $(@)" | ||
|
||
fixtures/set035-composer-files-autoload/composer-variable-access/vendor: fixtures/set035-composer-files-autoload/composer-variable-access/composer.lock | ||
composer --working-dir=fixtures/set035-composer-files-autoload/composer-variable-access install --no-dev --no-scripts | ||
touch -c $@ | ||
fixtures/set035-composer-files-autoload/composer-variable-access/composer.lock: fixtures/set035-composer-files-autoload/composer-variable-access/composer.json | ||
@echo "$(@) is not up to date. You may want to run the following command:" | ||
@echo "$$ composer --working-dir=fixtures/set035-composer-files-autoload/composer-variable-access update --lock && touch -c $(@)" | ||
|
||
build/set038/phpunit: | ||
rm -rf $(E2E_PHPUNIT_DIR) || true | ||
git clone --depth=1 --single-branch [email protected]:sebastianbergmann/phpunit.git $@ | ||
|
39 changes: 39 additions & 0 deletions
39
fixtures/set035-composer-files-autoload/check-non-prefixed-files.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php declare(strict_types=1); | ||
|
||
if (!isset($GLOBALS['__composer_autoload_files'])) { | ||
// This is to mimic a scoped app that may access to the Composer related globals like | ||
// PHPStan does. | ||
echo 'Expected to be able to access the composer autoload files!'.PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
$composerAutoloadFiles = $GLOBALS['__composer_autoload_files']; | ||
|
||
$expectedPresentComposerAutoloadFiles = [ | ||
'a4a119a56e50fbb293281d9a48007e0e' => true, // vendor/symfony/polyfill-php80/bootstrap.php | ||
'60884d26763a20c18bdf80c8935efaac' => true, // included-file.php | ||
]; | ||
$expectedMissingComposerAutoloadFiles = [ | ||
'430aabe1de335715bfb79e58e8c22198' => true, // excluded-file.php | ||
]; | ||
|
||
$actualExpectedPresent = array_diff_key( | ||
$expectedPresentComposerAutoloadFiles, | ||
$composerAutoloadFiles, | ||
); | ||
$actualExpectedMissing = array_diff_key( | ||
$expectedMissingComposerAutoloadFiles, | ||
$composerAutoloadFiles, | ||
); | ||
|
||
if (count($actualExpectedPresent) !== 0) { | ||
echo 'Expected the following hashes to be present:'.PHP_EOL; | ||
echo var_export($actualExpectedPresent, true).PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
if (count($actualExpectedMissing) !== count($expectedMissingComposerAutoloadFiles)) { | ||
echo 'Expected the following hashes to be missing:'.PHP_EOL; | ||
echo var_export($actualExpectedMissing, true).PHP_EOL; | ||
exit(1); | ||
} |
12 changes: 12 additions & 0 deletions
12
fixtures/set035-composer-files-autoload/composer-variable-access/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"bin": "index.php", | ||
"autoload": { | ||
"files": [ | ||
"included-file.php", | ||
"excluded-file.php" | ||
] | ||
}, | ||
"require": { | ||
"symfony/polyfill-php80": "^1.28" | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
fixtures/set035-composer-files-autoload/composer-variable-access/composer.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
fixtures/set035-composer-files-autoload/composer-variable-access/excluded-file.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
if (!function_exists('test_global_function')) { | ||
function test_global_function() {} | ||
} |
5 changes: 5 additions & 0 deletions
5
fixtures/set035-composer-files-autoload/composer-variable-access/included-file.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
if (!function_exists('test_global_function')) { | ||
function test_global_function() {} | ||
} |
5 changes: 5 additions & 0 deletions
5
fixtures/set035-composer-files-autoload/composer-variable-access/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require_once file_exists(__DIR__.'/vendor/scoper-autoload.php') | ||
? __DIR__.'/vendor/scoper-autoload.php' | ||
: __DIR__.'/vendor/autoload.php'; |
8 changes: 8 additions & 0 deletions
8
fixtures/set035-composer-files-autoload/composer-variable-access/scoper.inc.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'exclude-files' => [ | ||
'included-file.php', | ||
'vendor/symfony/polyfill-php80/bootstrap.php', | ||
], | ||
]; |
25 changes: 25 additions & 0 deletions
25
fixtures/set035-composer-files-autoload/composer-variable-access/vendor/autoload.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
if (PHP_VERSION_ID < 50600) { | ||
if (!headers_sent()) { | ||
header('HTTP/1.1 500 Internal Server Error'); | ||
} | ||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; | ||
if (!ini_get('display_errors')) { | ||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { | ||
fwrite(STDERR, $err); | ||
} elseif (!headers_sent()) { | ||
echo $err; | ||
} | ||
} | ||
trigger_error( | ||
$err, | ||
E_USER_ERROR | ||
); | ||
} | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInit945f0706470c9d6642a4450ed45b7c04::getLoader(); |
Oops, something went wrong.