Skip to content

Instantly share code, notes, and snippets.

@EvanAgee
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanAgee/ea46a3735145fe42d9af to your computer and use it in GitHub Desktop.
Save EvanAgee/ea46a3735145fe42d9af to your computer and use it in GitHub Desktop.
Send alert to HipChat with Behat test fails
<?php
/**
* 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();
$message =
'<h3>Whoopsie! There was a test failure!</h3>' . "<br>" .
'<strong>Domain:</strong> ' . $this->getMinkParameter('base_url') . "<br>" .
'<strong>Feature/Test:</strong> ' . $feature . "<br>" .
'<strong>Scenario:</strong> ' . $scenario . "<br>" .
'<strong>Step:</strong> ' . $step;
$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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment