-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Tests fail because expected exceptions are intercepted by ExceptionController #33478
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
Comments
To me, test cases like this one ( It works in 4.3 because the exception handler is replaced by PHPUnit and the response instance is never instantiated. To fix this in your project you can to add the TwigBundle or activate the HttpKernel's ExceptionListener service for your tests suite with a proper exception controller. |
The last, is what we have by default now as of 4.4 |
I faced this issue in #31398 (comment), but the other way around. See for example these tests in 4.3 https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/SecurityBundle/Tests/Functional/JsonLoginTest.php |
Well, tests aren't real live. And for functional tests like this one, a developer might want to check what exception specifically is raised. That's a bit complicated when parsing a human-readable error page. So, I can to a certain point understand why in general tests like this one have been built. For this specific test, the error page is fine though. Anyway, I'm rather concerned about test suites breaking when people start upgrading to Symfony 4.4. A documented migration path would be helpful. |
If a developer wants to check which exception is specifically raised, it is likely that they will not create a functional test with a request/response approach for that purpose, but a unit-specific test. I'm not really convinced why we would need a migration path for this kind of Functional test that in first place shouldn't happen. |
It doesn't seem so complicated IMHO, see https://github.com/symfony/symfony/pull/33479/files#diff-e84e5e830de34b1539d8bf85ed6042b5R27 |
And related to the title: "Tests fail because expected exceptions are intercepted by ExceptionController", I can say that "Tests pass because expected exceptions are not intercepted by ExceptionController" ;) that would be the correct behavior expected for these functional tests. The question now is: does it deserves a patch? |
Yes, the old behavior was rather an accident than documented behavior. I really like the new behavior because But the old behavior had been there since 2.x. My concern is that this very well crafted feature might break tests and leave developers clueless about what's wrong. Yes, those tests should maybe have been written differently in the first place.
No, but it deserves documentation, imho. |
Completely agree, thanks! I just added a comment in symfony/symfony-docs#12273 to not forget it. |
This PR was merged into the 4.3 branch. Discussion ---------- [SecurityBundle] Fix 4.3 tests forward compat | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #33478 | License | MIT | Doc PR | - Commits ------- f092331 Fix 4.3 tests forward compat
I think we can close here. The "broken" test has been fixed and upgrade path will be documented with symfony/symfony-docs#12273. |
Symfony version(s) affected: 4.4-dev
Description
#33271 introduced an error controller that renders error pages for exceptions. Before that, TwigBundle rendered error pages and if that bundle was missing, the exception bubbled up to the code that called
Kernel::handle()
.The new behavior might be more consistent, however it breaks tests that relied on the old behvior, like this one from SecurityBundle 4.3:
symfony/src/Symfony/Bundle/SecurityBundle/Tests/Functional/MissingUserProviderTest.php
Lines 16 to 26 in 828e5a4
The test fails if FrameworkBundle 4.4 is installed and if I downgrade FrameworkBundle to 4.3, the test is green.
PR #33271 patches the test on the 4.4 branch to parse the error page instead of catching the exception, but we cannot do that on 4.3 because then the test would not work with FrameworkBundle 4.3 anymore.
Also, this kind of looks like a BC break to me. Userland tests might run into similar issues.
ping @yceruto
How to reproduce
https://travis-ci.org/symfony/symfony/jobs/580647626
The text was updated successfully, but these errors were encountered: