CIUnit is a cool bridge between your CodeIgniter application and phpUnit.
Download the current fooStack v0.15 here!
(The cutting edge development version and older versions are accessible through the public mercurial repository at bitbucket.org / ciunit)
Install it as follows:
$active_group =in your database.php (YourProject/system/application/config directory) with:
$env_used = 'default'; //where default would be the name of your development setting if(defined('CIUnit_Version')){ $env_used .= '_test'; } $active_group = $env_used;
Congratulations you are done with installing fooStack!
Oh, wait, do you have phpUnit already installed?
http://www.phpunit.de/manual/current/en/installation.html
Once you have fooStack and phpUnit running:
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 fixturesThe 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 to format your data in). 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
$this->comments_fixt['second'];
Without writing any tests, typing "phpunit CIUnitAllTests.php" from within the application/tests/ciunit directory will already run a couple of tests - these make sure that CIUnit is correctly installed and works as expected.