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
Register shutdown function and throw exception if the file was not intercepted #13
Conversation
…tercepted in the current process by Infection's stream wrapper see infection/infection#1273
'Infection\'s IncludeInterceptor was not executed. Make sure you don\'t use any `file://` Stream Wrappers (like dg/bypass-finals)' | ||
); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How about a dedicated function that we will call from our side? Like
::setup(?callable $shutdownHandler)
- Isn't there a problem if a user happen to call
::intercept()
multiple times in a row?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a dedicated function that we will call from our side? Like
::setup(?callable $shutdownHandler)
do you mean in addition to current code, or instead? Could you please explain how we will use it?
What I wanted to achieve is
- to not modify any code where
Interceptor::intercept()
is used - to make the default shutdown handler
- to make it possible to override default shutdown handler to unit test the class. With the default shutdown handler - it's impossible to run unit tests without exit code equal to 0 - it always fails
So, example with ::setup()
will be useful for understanding.
Isn't there a problem if a user happen to call ::intercept() multiple times in a row?
Nothing bad. The first handler is executed, throws an exception, and the second one is not executed. So I would say in the current state it's safe to call ::intercept()
2 times. And I guess this will never be the case :)
But if you think we need to avoid it, I can wrap register_shutdown_handler()
with if
and do it only once regardless of how many times ::intercept()
is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @sanmai
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I think best way to tackle the issue would be to avoid callbacks and register_shutdown_handler()
altogether. IncludeInterceptor's job is to make intercept happen. It is not their job to control for this. That's one argument. Another reason to avoid register_shutdown_handler()
is that it is difficult to catch exceptions thrown from there.
So I think $wasIntercepted
is fine and good, only missing here is an accessor to read it. If we'd have a method ::wasIntercepted()
, we can call it, say, from here, and then we'll be free to do whatever we want, be it an exception, or a different exit code. (I hope there is a way, I just don't see it atm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then we'll be free to do whatever we want, be it an exception, or a different exit code.
but where we can do it? Mentioned code becomes an autoloader.php
for test framework. And this is the only one place where Infection has custom code for executed test suite.
And register_shutdown_handler()
was a workaround to add "after test framework execution" event and do some checks there.
So, without using register_shutdown_handler()
, how would you accomplish it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Al very least we can use this register_shutdown_handler()
inside mentioned autoloader.php
, but let me see if there's a better way.
Closing in favor of dg/bypass-finals#9 (comment) |
Register shutdown function and throw exception if the file was not intercepted in the current process by Infection's stream wrapper
see infection/infection#1275
When the project uses https://github.com/dg/bypass-finals, this lib unregisters Infection's stream wrapper and registers its own. It leads to Mutant (mutated file) not being used instead of original one.
Thus, all mutants are escaped.
With this update, Infection's user will see an error in the Infection's log with a clear message:
Before:
After:
And part of the log file: