Functional testing with Selenium and PHPUnit

Installing this stuff is simple in principle but a bit of a pig in practice

1. Install pear
download http://pear.php.net/go-pear.phar
sudo php /tmp/go-pear.phar

2. Install PHPUnit
pear config-set auto_discover 1
sudo pear channel-discover pear.symfony.com
pear install --alldeps pear.phpunit.de/PHPUnit
sudo pear install phpunit/DbUnit
sudo pear install phpunit/PHPUnit_Story

3. Install PHPUnit selenium package
pear install phpunit/PHPUnit_Selenium

4. Install Selenium Server
Download a distribution archive of Selenium Server. http://seleniumhq.org/download/
Unzip the distribution archive and copy selenium-server-standalone-2.9.0.jar (check the version suffix) to /usr/local/bin, for instance.
Start the Selenium Server server by running java -jar /usr/local/bin/selenium-server-standalone-2.9.0.jar

Then execute test file using
phpunit --colors testSubmitLoginForm test.php

PHPUnit 3.7.9 by Sebastian Bergmann.

..

Time: 30 seconds, Memory: 5.25Mb

OK (2 tests, 3 assertions)

All sounds simple but in reality several hours of dicking around with Pear channels may ensue before final success…

Useful links:
http://seleniumhq.org/download/
http://net.tutsplus.com/tutorials/php/how-to-use-selenium-2-with-phpunit/#close=1
http://www.phpunit.de/manual/current/en/selenium.html
http://devzone.zend.com/1014/acceptance-testing-of-web-applications-with-php/