It's
$event->getException()
Question
I'm working on integrating Behat with HipChat and I've got the following code so far.
/**
* Send an alert to HipChat when a test fails
*
* @AfterStep
*/
public function notifyHipchat(Behat\Behat\Event\StepEvent $event)
{
if ($event->getResult() === Behat\Behat\Event\StepEvent::FAILED) {
$step = $event->getStep();
$feature = $step->getParent()->getFeature()->getTitle();
$scenario = $step->getParent()->getTitle();
$step = $step->getType() . ' ' . $step->getText();
$error = '!!!!NEED CODE FOR THIS!!!!';
$current_page = $this->getSession()->getCurrentUrl();
$message =
'<img src="http://dl.dropboxusercontent.com/u/9451698/fail.gif" width="32" height="32" /> <strong>Whoopsie! There was a test failure!</strong>' . "<br>" .
'<strong>Domain:</strong> <a href="'.$this->getMinkParameter('base_url').'">' . $this->getMinkParameter('base_url') . "</a><br>" .
'<strong>Test Instance:</strong> ' . $this->getMinkParameter('files_path') . "<br>" .
'<strong>Feature/Test:</strong> ' . $feature . "<br>" .
'<strong>Scenario:</strong> ' . $scenario . "<br>" .
'<strong>Step:</strong> ' . $step . "<br>" .
'<strong>Current Page:</strong> <a href="'.$current_page.'">' . $current_page . '</a>';
$hipchat_url = 'https://api.hipchat.com/v1/rooms/message?auth_token='.getenv('HIPCHAT_AUTH_TOKEN').'&room_id='.getenv('HIPCHAT_ROOM_ID').'&from=Behat&color=red¬ify=1&message=' . urlencode($message);
$hipchat_message = file_get_contents($hipchat_url);
}
}
Which is working great but it only returns the test step that failed, it doesn't tell me what the actual error was. How do I access the exception that was thrown by the failed step? Thanks!
Solution
It's
$event->getException()