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
Compatibility with composer-bin-plugin #1897
Comments
Hi!
I think it's a bad idea in the current state of things. As you noted, infection need to autoload your code. So if you install it in a different
Using Infection PHAR would be no different if it was a regular PHAR. However Infection uses PHP-Scoper to address those issues. As the main contributor and a heavy user of A possible solution however, would be to do like PHPStan, i.e. have a proxy package which ships the isolated PHAR. I do not know how that works with extensions though, IIRC PHPStan managed to get around with it, I do not know what it entails for Infection. |
Thank you for the fast and detailed answer! Of course, if Infection needs to autoload project dependencies, it makes it impossible to use it with But I still don't completely understand why Infection needs to load project's dependencies. I thought that it uses PHPUnit CLI to run tests and PHP-Parser to parse sources; but perhaps I'm missing something, maybe reflection is also used. Anyway, the tool is great and helps a lot. |
Yes :) It uses parses the AST of the source code and may leverage reflection for some mutations. It could be delegated to BetterReflection at some point, but not sure what the performance impact would be. |
Is your feature request related to a problem? Please describe.
I don't know if it's bug report or feature request. I'm using
bamarni/composer-bin-plugin
to isolate my tools' dependencies, and I would like to be able to use it with Infection, too.In my case the problem was
thecodingmachine/safe
package - it throwed a fatal error during autoloading (thecodingmachine/safe#422, probably):I've started to investigate and found that to fix #795 issue Infection includes project's autoloader. But this solution creates incompatibility issue with
bamarni/composer-bin-plugin
.What in fact happens:
composer-bin-plugin
introduces "namespaces" for Composer installations and enables installing tools independently in sub-directories likevendor-bin/infection
. When I install Infection in such manner and try to runvendor-bin/infection/vendor/bin/infection --version
, I'm getting an error, because Infection also includes project autoloader (that uses older version of Safe package with unsolved thecodingmachine/safe#253 issue).Describe the solution you'd like
The origin of the problem is probably in
thecodingmachine/safe
package, but it's Infection that triggers it. Maybe it's possible to avoid this behavior? Remove it or, at least, enable switching it off.Describe alternatives you've considered
Alternative is to use Infection as PHAR, but it's impossible to use PHAR for tools that use plugins (such as Psalm). It would be convenient to use a single technique for all tools.
The text was updated successfully, but these errors were encountered: