Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct the Composer autoload #864

Merged
merged 11 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .makefile/e2e.file
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down Expand Up @@ -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 git@github.com:sebastianbergmann/phpunit.git $@
Expand Down
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);
}
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"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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() {}
}
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() {}
}
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';
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',
],
];
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();
Loading