Skip to content
Permalink
Browse files

Modifiy onNotSuccessfullTest method to match the signature of the new…

… onNotSuccessfullTest phpunit method and debugResponse method to match the new 500 error Symfony page markup.
  • Loading branch information...
petrero
petrero committed Jan 16, 2019
1 parent afdddb1 commit e2d133a1fdca38a73f7464fa89b2c2ae50ef6015
Showing with 30 additions and 21 deletions.
  1. +30 −21 tests/ApiTestCase.php
@@ -64,7 +64,7 @@ public function tearDown(){
}
protected function onNotSuccessfulTest(Exception $e)
protected function onNotSuccessfulTest(\Throwable $t)
{
if ($lastResponse = $this->getLastResponse()) {
$this->printDebug('');
@@ -75,7 +75,7 @@ protected function onNotSuccessfulTest(Exception $e)
$this->debugResponse($lastResponse);
}
throw $e;
throw $t;
}
private function purgeDatabase(){
@@ -96,6 +96,7 @@ protected function printLastRequestUrl(){
$this->printDebug('No request was made.');
}
}
protected function debugResponse(ResponseInterface $response)
{
foreach ($response->getHeaders() as $name => $values) {
@@ -121,39 +122,38 @@ protected function debugResponse(ResponseInterface $response)
if ($isValidHtml) {
$this->printDebug('');
$crawler = new Crawler($body);
// very specific to Symfony's error page
$isError = $crawler->filter('#traces-0')->count() > 0
|| strpos($body, 'looks like something went wrong') !== false;
$isError = $crawler->filter('.trace-line ')->count() > 0
|| strpos($body, 'Symfony Exception') !== false;
if ($isError) {
$this->printDebug('There was an Error!!!!');
$this->printDebug('');
} else {
$this->printDebug('HTML Summary (h1 and h2):');
}
// finds the h1 and h2 tags and prints them only
foreach ($crawler->filter('h1, h2')->extract(array('_text')) as $header) {
// avoid these meaningless headers
if (strpos($header, 'Stack Trace') !== false) {
continue;
}
if (strpos($header, 'Logs') !== false) {
continue;
foreach ($crawler->filter('.exception-message-wrapper h1')->extract(array('_text')) as $text) {
$text = $this->removeLineBreaks($text);
if ($isError) {
$this->printErrorBlock($text);
} else {
$this->printDebug($text);
}
}
// remove line breaks so the message looks nice
$header = str_replace("\n", ' ', trim($header));
// trim any excess whitespace "foo bar" => "foo bar"
$header = preg_replace('/(\s)+/', ' ', $header);
foreach ($crawler
->filter('.trace-line')
->first()
->extract(array('_text')) as $text
){
$text = $this->removeLineBreaks($text);
if ($isError) {
$this->printErrorBlock($header);
$this->printErrorBlock($text);
} else {
$this->printDebug($header);
$this->printDebug($text);
}
}
/*
* When using the test environment, the profiler is not active
* for performance. To help debug, turn it on temporarily in
@@ -177,6 +177,15 @@ protected function debugResponse(ResponseInterface $response)
}
}
protected function removeLineBreaks($text){
// remove line breaks so the message looks nice
$text = str_replace("\n", ' ', trim($text));
// trim any excess whitespace "foo bar" => "foo bar"
$text = preg_replace('/(\s)+/', ' ', $text);
return $text;
}
/**
* Print a message out - useful for debugging
*

0 comments on commit e2d133a

Please sign in to comment.
You can’t perform that action at this time.