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

Make interceptor resilient to file not found warnings #846

Merged
merged 10 commits into from
Nov 26, 2019

Conversation

nico-incubiq
Copy link
Contributor

@nico-incubiq nico-incubiq commented Nov 24, 2019

This PR:

  • Covered by tests

Fixes #836

Warnings are converted to Errors while running tests under PHPUnit. But due to the fact the interceptor wrapper disables itself before calling fopen, and re-enables itself just after, if an error is thrown in between, the interceptor is never re-enabled.

This is actually the issue we experienced with @Bilge. Because we use Symfony, and one of the cache components attempts to read files in ./var/cache/test/pools to determine hits and misses as part of the Kernel initialisation. Which means that very early on the interceptor gets disabled, and then mutations are never really applied to the code, so all mutants appear to be escaping.

--I've only added the try/finally in the stream_open function because I didn't have any example for the other functions, but tell me if you'd rather do the same for all functions on principle.--

I have added a try/finally to all functions disabling and re-enabling the interceptor around a system call, and added specific tests for all of them.

@nico-incubiq
Copy link
Contributor Author

nico-incubiq commented Nov 24, 2019 via email

if (isset($this->context)) {
$this->fp = fopen($path, $mode, (bool) $options, $this->context);
} else {
$this->fp = fopen($path, $mode, (bool) $options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it is in any way the point of this PR, but why can't this if/else branch be condensed down to just the following?

$this->fp = fopen($path, $mode, (bool) $options, $this->context ?? null);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could even be fopen($path, $mode, (bool) $options, $this->context) all the time, as $this->context defaults to null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BackEndTea I hope that's fine by you, I applied this suggestion throughout the file as it makes the code a lot clearer to understand.

@BackEndTea
Copy link
Member

It seems passing in null explicitly, instead of passing in nothing has a different result. Could you revert that change?

@nico-incubiq
Copy link
Contributor Author

Done

Copy link
Contributor

@Bilge Bilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that my review counts for anything, but looks great to me! 👍

@BackEndTea
Copy link
Member

Test failures are due to the interceptor not being 'cleaned up'. That means that after every test we would also need to do a ::disable().

I would also be okay with having this in the tearDown method, and having any errors it creates silenced. The same way as it is in the tearDownAfterClass method.

@nico-incubiq
Copy link
Contributor Author

Okay i've done that, interestingly it wasn't failing locally for me. I've noticed one of the tests using chmod was not passing on Windows, so I fixed that too.

Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a bugfix, could you please target 0.14 branch so we can release it right after the merge?

@nico-incubiq nico-incubiq changed the base branch from master to 0.14 November 25, 2019 20:39
@nico-incubiq
Copy link
Contributor Author

nico-incubiq commented Nov 25, 2019

i'd need to do a rebase to do that, there's quite a lot of commits in my branch which aren't in 0.14 as it was based on master. done i've also address the @requires tag

@maks-rafalko maks-rafalko merged commit fc88dc8 into infection:0.14 Nov 26, 2019
@maks-rafalko
Copy link
Member

Thank you @nico-incubiq for this contribution!

@maks-rafalko
Copy link
Member

Released: 0.14.3

maks-rafalko pushed a commit that referenced this pull request Nov 26, 2019
* Make interceptor resilient to file not found warnings

* Don't add a property just to test something

* Also prevent directory includes from breaking the interceptor

* Small code improvements suggested on PR

* Protect all functions which disable the interceptor against errors

* Undo passing null instead of not passing anything

* Disable interceptor after each test

* Fix Code Style

* Skip test not passing on Windows

* Use requires to skip test on Windows
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 this pull request may close these issues.

None yet

5 participants