Last active
March 29, 2018 10:44
-
-
Save mrself/5a9e5b5ed35e4b6178f15d86058a74e3 to your computer and use it in GitHub Desktop.
Track errors in symfony when testing with phpunit when using WebTestCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testSmth() { | |
$this->client = static::createClient(); | |
$crawler = $this->client->request('GET', '/my-test-page'); | |
if ($this->client->getResponse()->getStatusCode() !== 200) { | |
dump($crawler->filter('.text-exception')->first()->text()); | |
dump($crawler->filter('.traces > li')->eq(0)->text()); | |
dump($crawler->filter('.traces > li')->eq(1)->text()); | |
throw new \Exception('Request to /my-test-page was not successfull'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testSmth() { | |
$this->client = static::createClient(); | |
$crawler = $this->client->request('GET', '/my-test-page'); | |
if ($this->client->getResponse()->getStatusCode() !== 200) { | |
$profile = $this->client->getProfile(); | |
$exceptionProfile = $profile->getCollector('exception'); | |
$trace = $exceptionProfile->getTrace(); | |
$trace = array_slice($trace, 0, 5); | |
$trace = array_map(function($i) { | |
unset($i['short_class']); | |
unset($i['namespace']); | |
if ($i['file']) { | |
$root = $this->container->getParameter('kernel.root_dir'); | |
$root = str_replace('app', '', $root); | |
$i['file'] = str_replace($root, '', $i['file']); | |
unset($i['class']); | |
$i['file'] .= $i['type'] . $i['function'] . ':' . $i['line']; | |
unset($i['line']); | |
unset($i['type']); | |
unset($i['function']); | |
} | |
return $i; | |
}, $trace); | |
dump($trace); | |
throw new \Exception($exceptionProfile->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment