2014-05-15 25 views
0

我正在将Behat与HipChat集成,到目前为止我已经得到了以下代码。在Behat测试步骤中显示返回的具体错误

/** 
    * 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

这是

$event->getException() 
+0

真的吗?我已经尝试了几次,但是从命令行运行时没有给出与测试相同的回报。我会再试一次,非常感谢! –

+0

这样做!输出结果并不像控制台那么简洁,但是我可以将其分解为我所需要的。非常感谢! –

相关问题