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
[HttpFoundation] Make test constraints less verbose #42948
Comments
The way I've come to not have this verbose output is to use/override PHPUnit /**
* Override PHPUnit fail method
* to catch "assertResponse" exceptions
*
* @link https://devdocs.io/phpunit~9/fixtures
*/
protected function onNotSuccessfulTest(\Throwable $t): void
{
// If "assertResponse" is found in the trace, custom message
if (strpos($t->getTraceAsString(), 'assertResponse') > 0) {
$arrayMessage = explode("\n", $t->getMessage());
$message = $arrayMessage[0] . "\n" . $arrayMessage[1];
$this->fail($message);
}
// Other Exceptions
throw $t;
}``` |
Thank you for this issue. |
Nope |
👍 PR welcome |
Thank you for this issue. |
Could I get a reply or should I close this? |
I still plan to get this done. An aspirational goal os to make it part of our "upgrade to phpunit 10" initiative. |
There is an option to disable the HTML error page in WebTestCase. Does it solves this issue? $client = self::createClient();
$client->catchExceptions(false);
$client->request('GET', $uri);
$this->assertResponseIsSuccessful(); |
Thank you for this issue. |
Could I get a reply or should I close this? |
Keep open. |
@GromNaN FYI using |
With a simple error 500 or 404, I get about 40 kilobytes of text. This is enough for any console buffer to run out. In addition, PHPUnit begins to complain about lack of memory. |
Description
I have been wondering about a behaviour present when running a PHPUnit functional test in a command line.
Current behaviour: when using the off the shelf test assertions, such as
assertResponseIsSuccessful()
, each constraint includes the entire response body viaadditionalFailureDescription()
method.This makes the PHPUnit output quite verbose, thanks to the beautiful error page generated by Symfony, which is great via the browser, but when it comes out as a plaintext, it's not so handy.
There is a good chance I'm doing something wrong - maybe I'm trying to solve a wrong problem, maybe there is a way to turn the error page off when accessing the page with the testing client. If so, please point me somewhere I can learn about it and read no more, and I apologise for wasting everyone's time.
If I'm right about the behaviour, then I'd like to propose changing it, because a single failed assertion generates so much clutter that it is difficult to navigate/read the test results.
I'm happy to create a PR for this, but before I jump into it, I'd like to collect some feedback.
My proposal:
Symfony\Component\HttpFoundation\Test\Constraint
, say$verbose = true
\Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait
BrowserKitAssertionsTrait
could define a default $verbose value, which could be overridden by individual test classes using the trait.All this can be done without affecting any existing functionality, providing the tests would be verbose by default.
What do you think?
Thanks for reading.
Example: Failed test in the current state, with the complete response body attached:
Example: without the response body, the error is still perfectly legible
The text was updated successfully, but these errors were encountered: