fooStack for CodeIgniter

CIUnit: Unit testing for CodeIgniter

CIUnit is a cool bridge between your CodeIgniter application and phpUnit.

Download the current fooStack v0.17 - for CI 1.7.2 here!

Download the slightly outdated fooStack v0.15 here - for CI 1.6.X, 1.7.1

For please be aware that the installation is slightly different! Have a look at the index.html file included in

(The cutting edge development version and older versions are accessible through the public mercurial repository at / ciunit)

2 minute Setup:

  1. Download and unzip the fooStack package in a temporary folder
  2. Copy the fooStack directory in your "YourProject/system/application/libraries" directory
  3. Copy the tests directory in your "YourProject/system/application" directory
  4. If you don't use the standard layout for your CodeIgniter project, change the first 2 paths in the file "YourProject/system/application/libraries/fooStack/fooBase/index.php"
  5. Replace the line that starts with
    $active_group =
    in your database.php ("YourProject/system/application/config" directory) with:
    $env_used = 'default'; //name of your development setting
      $env_used .= '_test';
    $active_group = $env_used;
  6. Create a new database setting that will act as the test database (it will always be cleared when you run tests!), that is named like your development setting but with a trailing '_test'. Note: CIUnit fixtures will insist on the trailing '_test' to prevent accidental data loss.

Congratulations you are done with setting up fooStack!

Oh, wait, do you have phpUnit already installed?

Once you have fooStack and phpUnit running:

Run tests:

Generating database fixtures:

Given you have tables in your test database (you should have the same as in the development database!), you can generate empty yaml fixtures like so: From within the tests directory type (make sure the fixtures directory is writable!):

php generate fixtures
The fixture files are then available in the tests/fixtures directory.

Using the fixtures is easy: Fill the yaml fixture files with the fixture data needed (yaml is a easily readable format for your data). Once this is done, call e.g.

$this->dbfixt('items', 'comments', 'users'); 
from within the test setup function. Then these table fixtures are assured to be loaded into your test database AND are available as test variables like so:
$this->items_fixt, $this->comments_fixt, $this->users_fixt.
E.g the second row of data in the comments table in your tests database is also available through

CIUnit tests itself

Without writing any tests, typing "phpunit CIUnitAllTests.php" from within the "YourProject/application/tests/ciunit" directory will already run a couple of tests - these make sure that CIUnit is correctly installed and works as expected.