-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ErrorHandler][FrameworkBundle] better error messages in failing tests #36003
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
[ErrorHandler][FrameworkBundle] better error messages in failing tests #36003
Conversation
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
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.
Cool! No more blind errors when using this testing API \o/
src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php
Outdated
Show resolved
Hide resolved
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.
I added some comments, thank you!
Thank you @guillbdx. |
Nice! This was the one thing missing from the new testing assertions. Thanks for working on this. |
I'm getting an nginx error caused by a too large X-Debug-Exception header ( |
Hello @eng1neer and thank you for reaching out. This tracker is meant for tracking bugs and feature requests. If you are looking for support, you'll get faster responses by using one of our official support channels:
See https://symfony.com/support for more support options. |
Hey, @derrabus thanks for taking the time to flag my message as off-topic. I would argue that this is actually a bug. Stuffing data of an arbitrary length into HTTP headers is a bad idea. Most of the web servers impose a limit on the amount of data that can be transmitted in HTTP headers and this limit is not too big (4-8KB for Apache or Nginx). You can easily exceed it with a few kilobytes of text in the exception message which leads to an unexpected error page generated by the webserver. There should be other, more appropriate ways to pass exception information in tests that will not intervene with the usual development workflow. |
@eng1neer All right then, please file a bug report. |
…ssages in failing tests (guillbdx) This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [ErrorHandler][FrameworkBundle] better error messages in failing tests | Q | A | ------------- | --- | Branch? | master for features | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix symfony#32752 | License | MIT | Doc PR | Purpose of this PR is to enhance tests by giving a way to report an exception that occured during the processing of the request. The ErrorHandler will add an X-Debug-Exception, and the assertThat() method of WebTestCase will throw an exception if this header exists and status code is 5xx. In practice, this adds the "Caused by" section in this example: ``` Time: 374 ms, Memory: 20.00 MB There was 1 failure: 1) App\Tests\Controller\HomeControllerTest::testC Failed asserting that the Response has header "Content-Type" with value "application/json". /srv/symfony/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php:132 /srv/symfony/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php:66 /srv/blog/tests/Controller/HomeControllerTest.php:29 Caused by Exception: This a test exception. in /the/file.php:139 Stack trace: [...] ``` Commits ------- 0da9469 [ErrorHandler][FrameworkBundle] better error messages in failing tests
Purpose of this PR is to enhance tests by giving a way to report an exception that occured during the processing of the request.
The ErrorHandler will add an X-Debug-Exception, and the assertThat() method of WebTestCase will throw an exception if this header exists and status code is 5xx.
In practice, this adds the "Caused by" section in this example: