Two years ago I blogged about a Xinc (R.I.P?) plugin that growls each build status for any via Xinc continuously integrated project. Since I'm using PHPUnit more and more lately, especially in continuous testing sessions (sprints without hitting the continuous integration server), my dependence on a fast and more visual feedback loop rose. In this post I'll provide an easy solution that meets these requirements by utilizing PHPUnit's test listener feature.What's the motivation, yo?While doing story or feature sprints embedded in a continuous testing approach I first used a combination of stakeout.rb and PHPUnit's --colors option to radiate the tests status, but soon wasn't that satisfied with the chosen route as it happened that the console window got superimposed with other opened windows (e.g. API Browser, TextMate etc.) especially on my 13,3" MacBook.
To overcome this misery I decided to utilize PHPUnit's ability to write custom test listeners and to implement one that radiates the test status in a more prominent and sticky spot via Growl.Implementing the Growl test listenerSimilar to the ticket listener plugin mechanism I blogged about earlier PHPUnit also provides one for test listeners. This extension mechanism allows to bend the test result formatting and output to the given needs and scenarios a developer might face and therefore is a perfect match.
To customize the test feedback and visualization the test listener has to implement the provided PHPUnit_Framework_Testlistener interface. A few keystrokes later I ended up with the next shown implementation, which is also available via a GitHub gist, supporting the previous stated requirements.
<?php
require_once('PHPUnit/Framework.php');
require_once('PHPUnit/Util/Timer.php');
class PHPUnit_Extensions_TestListener_GrowlTestListener
implements PHPUnit_Framework_Testlistener
{
const TEST_RESULT_COLOR_RED = 'red';
const TEST_RESULT_COLOR_YELLOW = 'yellow';
const TEST_RESULT_COLOR_GREEN = 'green';
private $_errors = array();
private $_failures = array();
private $_incompletes = array();
private $_skips = array();
private $_tests = array();
private $_suites = array();
private $_endedSuites = 0;
private $_assertionCount = 0;
private $_startTime = 0;
private $_successPicturePath = null;
private $_incompletePicturePath = null;
private $_failurePicturePath = null;
/**
* @param string $successPicturePath
* @param string $incompletePicturePath
* @param string $failurePicturePath
*/
public function __construct($successPicturePath, $incompletePicturePath,
$failurePicturePath)
{
$this->_successPicturePath = $successPicturePath;
$this->_incompletePicturePath = $incompletePicturePath;
$this->_failurePicturePath = $failurePicturePath;
}
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
$this->_errors[] = $test->getName();
}
public function addFailure(PHPUnit_Framework_Test $test,
PHPUnit_Framework_AssertionFailedError $e, $time)
{
$this->_failures[] = $test->getName();
}
public function addIncompleteTest(PHPUnit_Framework_Test $test,
Exception $e, $time)
{
$this->_incompletes[] = $test->getName();
}
public function addSkippedTest(PHPUnit_Framework_Test $test,
Exception $e, $time)
{
$this->_skips[] = $test->getName();
}
public function startTest(PHPUnit_Framework_Test $test)
{
}
public function endTest(PHPU
Truncated by Planet PHP, read more at the original (another 11107 bytes)



Several months ago
Since
As the days are rapidly getting shorter, my reading appetite grows potentially and this evening I finished the 'Zend Framework 1.8 Web Application Development' book written by