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

Add possibility to prepend a file to generated bootstrap #1681

Closed
shvlv opened this issue Apr 11, 2022 · 9 comments
Closed

Add possibility to prepend a file to generated bootstrap #1681

shvlv opened this issue Apr 11, 2022 · 9 comments

Comments

@shvlv
Copy link

shvlv commented Apr 11, 2022

Is your feature request related to a problem? Please describe.
I'm relatively new to Infection. There is an amazing library. Thanks a lot!

I'm trying to combine Infection with https://github.com/antecedent/patchwork (don't ask me why I need that magic: I work with WordPress so global functions are everything).

The problem is Patchwork.php file should be included first. But Infection creates the new bootstrap file and adds user-generated bootstrap in the end. So magic doesn't work.

Describe the solution you'd like
I tested a dirty workaround: add require '/global_path/vendor/antecedent/patchwork/Patchwork.php'; to the

. All works as expected.

So is it possible to add a CLI flag/configuration to allow prepending to auto-generated bootstrap?

Describe alternatives you've considered
I tried PHP Unit flags like --test-framework-options="--prepend=vendor/antecedent/patchwork/Patchwork.php --process-isolation" but without success.

Additional context

@maks-rafalko
Copy link
Member

maks-rafalko commented Apr 11, 2022

Hello, thanks for using Infection!

Have you tried bootstrap configuration setting? (see https://infection.github.io/guide/usage.html)

infection.json:

{
    "bootstrap": "./custom-bootstrap.php"
}

It's possibly now what you are looking for, but could you please try it? If this doesn't work, I'm ok with implementing a new option and corresponding setting for this. Help is much appreciated.

@shvlv
Copy link
Author

shvlv commented Apr 12, 2022

Hi, @maks-rafalko!
I've tried the bootstrap setting but without success. Looks like bootstrap is included once (before command run) but we need to include the file before every test.

I will try to prepare PR with prepend configuration option.

@maks-rafalko
Copy link
Member

I see.

Are you sure it works as expected when you do "dirty workaround"? Does Infection have killed and escaped mutants in this case?

Why I'm asking is because Patchwork uses Stream Wrapper, and I'm not sure it is compatible with Infection's stream wrapper.

We have a similar issue with bypass-finals:

Please, make sure it's (not) the same issue, just to not waste your time on the implementation.

@shvlv
Copy link
Author

shvlv commented Apr 12, 2022

I've created a test repository.
There is my quick fix - shvlv@ba60d31

There is the branch with the original infection - https://github.com/shvlv/infection-patchwork (GitHub Action - https://github.com/shvlv/infection-patchwork/actions/runs/2157223680)

There is the branch with the patched infection - https://github.com/shvlv/infection-patchwork/tree/patched-infection (GitHub Action - https://github.com/shvlv/infection-patchwork/actions/runs/2157215149)

I'm not sure about internal logic but seems the fix works for my case...

@maks-rafalko
Copy link
Member

ok, seems like you are right. One more question: do you have an understanding why without patched Infection version all the mutants are escaped?

@shvlv
Copy link
Author

shvlv commented Apr 13, 2022

I don't know.
And moreover seems my test was wrong because apply_filters is the core brain/monkey feature which is not fully related to Patchwork (and this fact gets stuff more complicated).

I tested locally again with pure Patchwork redefinition and get all mutants killed because of undefined functions. So nothing works again.

So while the issue exists my feature request is not valid, you were right :). Feel free to close or I will try to find additional information. But looks like the issue is more complex than at first glance.

@shvlv
Copy link
Author

shvlv commented Apr 14, 2022

My new insight.
The assumption about including Patchwork.php file as early as possible is not valid (setUp place plays nicely, especially with processIsolation PHP Unit option). For this case, mutations are escaped https://github.com/shvlv/infection-patchwork/actions/runs/2166059365 because the Patchwork file stream overrides the Infection stream so the tests are run for non-mutated files in fact.

So only possible for me without deep coding is only to ignore classes that have global functions. So Infection could do mutation for normal tests and ignores Patchwork-required tests. https://github.com/shvlv/infection-patchwork/actions/runs/2166073422

The solution is not very good because the same class could be tested in a functional way (without mocking) and with mocking.

But my knowledge is not enough to handle the issue properly...

@maks-rafalko
Copy link
Member

yes, I also have no right solution, unfortunately.

Since Infection doesn't support mutation functions and does not work with any libs that use Stream Wrappers, can we close this particular feature request?

@shvlv
Copy link
Author

shvlv commented Apr 21, 2022

yes, we can. thanks for your support!

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

2 participants