All code contributed to the repository should have corresponding tests. As a matter of fact, This section outlines the tools required to run the test suite, how to install them and a guideline on how to write unit tests for the platform.

The SwiftRiver test suite runs on top PHPUnit which can be installed using the PEAR installer. Depending on your OS distribution and/or your PHP environment, you may need to install PEAR or update your existing PEAR installation.

Installing PEAR

NOTE: If you already have PHP PEAR installed, you may skip this section

OS-X (Snow Leopard, Lion)

$ curl http://pear.php.net/go-pear.phar > pear.php
$ sudo php -q pear.php

Debian/Ubuntu

$ sudo apt-get install php-pear

CentOS/Fedora

$ sudo yum -y install php-pear

Required PHP Tools

Once you have PHP PEAR installed, the following PHP tools should be installed using the PEAR installer:

Setting up Your Test Environment

To install PHPUnit and the required extensions, run the following:

$ sudo pear config-set auto_discover 1
$ sudo pear install pear.phpunit.de/PHPUnit
$ sudo pear install phpunit/DbUnit

Running the Test Suite

Before running the test suite, you must have performed the following:

NOTE: As of this writing, the kohana/unittest module does not lowercase the PDO driver type

To run the test suite, run the following command:

$ phpunit --colors --bootstrap=/path/to/application/tests/bootstrap.php --exclude-group=kohana /path/to/modules/unittest/tests.php

Writing Tests

All unit tests (PHPUnit) are in the application/tests directory. The structure of this (tests) directory mirrors that of the application/classes directory. See the illustration below:

General Guidelines

Database Testing

Database testing is for the model classes i.e. classes located in application/classes/Model. The following guidelines apply to unit tests for models: