Last active
August 29, 2015 14:01
-
-
Save EvanAgee/ea46a3735145fe42d9af to your computer and use it in GitHub Desktop.
Send alert to HipChat with Behat test fails
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
<?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¬ify=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