Why am I using PHPUnit instead of Drupal's own Simpletest module?
While developing I like to continually write Unit-Tests for my module as I go. For that I need a fast way to execute those tests - so it is not possible to do a full DB-bootstrap (or even a reload of a cached DB-script) after every test. Instead I try to really build unit-tests that don't modify the database. Therefore I need to make heavy use of Mock- & Stub-Objects. PHPUnit provides a nice API for building the objects - Drupal's simpletest doesn't.
Set-up your test environment
To execute those scripts you need to checkout my gist-repository. To execute Unit-Tests in the command-line simply go to a Drupal site (ie. /var/www/drupal/sites/default) and use dphpunit.bash just as you would use the phpunit command.
How does it work?
The script consists of 3 files:
- dphpunit.bash - which simply invokes drun-dphpunit.php with a few extra parameters. It's needed because PHP is incapable of dealing with symlinks correctly.
- drun-dphpunit.php - which is basically the same as the upstream phpunit runner, except that it handles the extra parameter
- bootstrap.inc.php - which makes a Drupal bootstrap very similar to drush
Feel free to drop me a comment …