Dan Poltawski's blog

Notifiying end of PHPunit executions

phpunit notify screenshot

Whilst integrating issues into Moodle it’s a multiple times per day occurrence to run phpunit tests on the whole Moodle codebase. Each day we add more and more tests and so the time taken to run these tests increases gradually. I’m not one for swordsmanship on wheely chairs, so whilst waiting for phpunit tests to run I’ll generally move onto another task, then frequently i’d forget completely that the phpunit run was going on in the background and not know what the phpunit output was showing me, need to run the tests again and fall into the same trap!

In order to resolve this situation I was inspired by Brett Terpstra’s post about using the ruby gem terminal-notifier to send messages to Mountain Lion’s notification center and decided to use this to remind me of phpunit executions.

After installing terminal-notifier and using Bret’s finished.rb script I added a bash function for phpunit:

	function phpunit() {
	    vendor/bin/phpunit $@
	    if [[ $? == 0 ]]; then
	        finished "phpunit OK"
	    else
	        finished "phpunit FAILED"
	    fi
	}

In order that I don’t miss a phpunit run I’ve configured the notifications to be ‘Alert style notifications’ (configured in OS X Preferences > Notifications > terminal-notifier) which works great, the only remaining issue is there does not seem to be a way to dismiss alerts using keyboard shortcuts.