fooStack for CodeIgniter
CIUnit: Unit testing for CodeIgniter
CIUnit is a cool bridge between your CodeIgniter application and phpUnit.
Install it as follows:
- Copy the fooStack directory in your YourProject/system/application/libraries directory
- Copy the tests directory in your YourProject/system/application directory
- Replace the CodeIgniter.php file in your YourProject/system/codeigniter directory with the one of the package
- replace the line that starts with
$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;
- 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 ask for the trailing '_test' to prevent accidental data loss.
Congratulations you are done with installing fooStack!
Oh, wait, do you have phpUnit already installed?
http://www.phpunit.de/pocket_guide/3.2/en/installation.html
Once you have fooStack and phpUnit running:
Run tests:
- Run all tests from within the tests directory: "phpunit AllTests.php", or use "phpunit --verbose AllTests.php" to get more detailed output
- Run only a subgroup of tests, eg model tests, go into the tests/models directory and run "phpunit ModelAllTests.php"
- Consequently, for running just one particular test, change to this test's directory and type "phpunit testSomeStuff.php"
Generate 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:
php generate fixtures
,
the fixture files are then available in the fixtures directory
CIUnit tests itself
Without writing any tests, typing "phpunit AllTests.php" will already run a couple of tests - these make sure that CIUnit is correctly installed and works as expected.
You can always tell CIUnit later on not to run these tests, probably because you want to speed up your test suites.