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

Class Composer\InstalledVersions not found (again) #678

Closed
maks-rafalko opened this issue Jul 28, 2022 · 0 comments · Fixed by #712
Closed

Class Composer\InstalledVersions not found (again) #678

maks-rafalko opened this issue Jul 28, 2022 · 0 comments · Fixed by #712

Comments

@maks-rafalko
Copy link

maks-rafalko commented Jul 28, 2022

Bug report

Question Answer
PHP-Scoper version 3.16.0, 4.0.2
PHP version 8.1.7
Platform with version Manjaro (ArchLinux)
Composer 2.2.1
Github Repo https://github.com/martinssipenko/php-scoper-issue

This is basically a reopen of #532 with new details. It still doesn't work.

How to reproduce?

git clone [email protected]:martinssipenko/php-scoper-issue.git
cd php-scoper-issue

composer install

wget -q https://github.com/humbug/box/releases/download/4.0.2/box.phar --output-document=./box
chmod +x box

./box compile

# and test generated PHAR
./test.phar

Result:

PHP Fatal error:  Uncaught Error: Class "_HumbugBoxc78d51bc45e9\Composer\InstalledVersions" not found in phar:///tmp/temp/php-scoper-issue/test.phar/cli.php:8
Stack trace:
#0 /tmp/temp/php-scoper-issue/test.phar(14): require()
#1 {main}
 thrown in phar:///tmp/temp/php-scoper-issue/test.phar/cli.php on line 8

Workaround

If I add the following scoper.inc.php:

return [
    'exclude-classes' => [\Composer\InstalledVersions::class],
    'exclude-files' => ['vendor/composer/InstalledVersions.php'],
];

then, after generating new test.phar everything works as expected.

I think that PHP-Scoper (or Box) doesn't properly handle vendor/composer/InstalledVersions.php file. Without scoper.inc.php, this file is prefixed (has a prefix in a namespace), however vendor/composer/autoload_classmap.php contains not prefixed key:

<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',

    // ^^^^^^ look at this, it's not prefixed
);

Related to infection/infection#1708

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant