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

Support to load extraFiles from PHAR #3868

Open
filips123 opened this issue Jul 22, 2020 · 3 comments
Open

Support to load extraFiles from PHAR #3868

filips123 opened this issue Jul 22, 2020 · 3 comments

Comments

@filips123
Copy link

I have installed PHPUnit (and other dev-related tools, including Psalm) as PHAR using Phive to vendor/bin/phpunit. PHPUnit is not required as dev dependency in composer.json, so its classes won't load using autoloader, but will still be available when you run PHPUnit because PHAR will provide them. This will cause Psalm to think classes such as PHPUnit\Framework\TestCase do not exist and fail to analyze.

I tried to provide path to PHAR (vendor/bin/phpunit) in extraFiles option in config, both as file and directory, but this doesn't fix the problem. If I provide path as file, Psalm will load but continue to fail to recognise classes. If I provide path as directory, Psalm will fail to load and say that is not a directory.

Is it possible to provide support for loading extraFiles from PHARs? It would be very useful if you don't want to add too many dev tool dependencies to your project, causing slow installation time and possible dependency conflicts.

@psalm-github-bot
Copy link

Hey @filips123, can you reproduce the issue on https://psalm.dev ?

@xPaw
Copy link

xPaw commented Aug 10, 2020

This would indeed be nice. I'm also using it like this:

require __DIR__ . '/bugsnag.phar';
$bugsnag = \Bugsnag\Client::make( Config::$BugsnagKey, \Bugsnag\Client::ENDPOINT );

ERROR: MissingFile - bugsnag.phar:4:1 - Cannot find file phar:\bugsnag.phar\autoloader.php to include (see https://psalm.dev/107)
ERROR: UndefinedClass - Class or interface Bugsnag\Client does not exist (see https://psalm.dev/019)

@ro0NL
Copy link
Contributor

ro0NL commented Sep 20, 2021

Here's how i managed to do it

<extraFiles>
    <directory name="var/phpunit"/>
</extraFiles>
wget -O bin/phpunit.phar https://phar.phpunit.de/phpunit-9.phar && \
chmod +x bin/phpunit.phar && \
php -r "(new Phar('bin/phpunit.phar'))->extractTo('var/phpunit', null, true);"

Then in CI where phpunit is already available you could create a symlink instead.

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

No branches or pull requests

4 participants