显示Behat测试步骤中返回的特定错误

时间:2014-05-15 15:45:29

标签: php behat

我正在努力将Behat与HipChat集成,到目前为止,我已经获得了以下代码。

/**
   * 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" />&nbsp;&nbsp;<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&notify=1&message=' . urlencode($message);
        $hipchat_message = file_get_contents($hipchat_url);
    }
}

哪种方法效果很好,但它只返回失败的测试步骤,它没有告诉我实际错误是什么。如何访问失败步骤引发的异常?谢谢!

1 个答案:

答案 0 :(得分:1)

这是

$event->getException()