[5.5] Throw exception for non http exceptions when running tests #20724
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm having a problem when the following test throws a non-http exception:
For example I had his route that throws a
BadMethodCallException
with the messageMethod [validateAlphaNumeric] does not exist.
(the rulealpha_numeric
does not exist, it isalpha_num
).But the test still passes, for some reason! I think it has to do with the long HTML generated by Whoops. If I deactivate Whoops to render the exception with Symfony, the test fails but I still get a long HTML dumped in the console.
I spent a couple of hours trying different solutions and I think what makes the most sense here is to throw the exception when it is not a HTTP exception. So the test fails and the dev gets to see the actual error.
This shouldn't affect validation exceptions and other http exceptions.
I am aware of
with[out]ExceptionHandling
the problem is that I might be actually trying to test the validation (and therefore will need exception handling enabled) for example:This test fails, I get:
Session is missing expected key [errors]
. I however don't get the real reason why it failed (the method validateAlphaNumeric doesn't exist). I then have to go back to the test and callwithoutExceptionHandling
to understand what is going on.I could even get a false positive if for some reason I use
->assertSessionMissing('errors');
instead ofassertSessionHasErrors
.With this PR I will get the exception (even if exception handling is enabled).
Or maybe I am terrible wrong / missing something, in this case I appreciate if someone helps me to clarify this.