[eluser]Adrian Walls[/eluser]
Hi,
I am currently trying to implement a unit testing framework for an application I have written using CI. I have read through various posts on this forum and others about ways to implement this and decided to write my unit tests using CIUnit. However I have run into a few issues and was hoping someone somewhere had managed to set this up successfully and could possibly shed some light on my problems.
Firstly I am trying to test the controllers in my app. However in my controllers there are session variables are being checked, such as if a user is logged in. This causes the CIUnit test to fall over as these session variables have not been initialised. Is there a way I can set the session variables via the CIUnit test code so that they are initialised when called via the test run from the command line?
Secondly if I try to run tests against my model code I keep getting a DB error when running the tests. The error on the command line says:
Sorry, the name of your test database must end on '_test'.
This prevents deleting important data by accident.
And the CI log file shows the following error:
ERROR - 2008-08-22 18:22:22 --> Severity: Notice --> Undefined property: Controller::$db C:\Sites\dev\rhff\system\application\libraries\fooStack\Fixture.php 32
ERROR - 2008-08-22 18:22:22 --> Severity: Notice --> Trying to get property of non-object C:\Sites\dev\rhff\system\application\libraries\fooStack\Fixture.php 32
The line in question in Fixtures.php is:
Code:
$db_name_len = strlen($this->CI->db->database);
And it appears that this is empty???
The config/database.php file looks like:
Code:
$env_used = 'default'; //where default would be the name of your development setting
if(defined('CIUnit_Version')){
$env_used .= '_test';
}
$active_group = $env_used;
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "*****";
$db['default']['password'] = "*****";
$db['default']['database'] = "******_oms";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
I appreciate that there might be a lot of information in this one post covering a few different issues but I thought I'd just throw all the cards out on the table for now :-). If it generates a lot of response I'll break it up into separate posts but for now I'll keep it condensed into this post.
I look forward to hearing other people’s experiences with implementing CIUnit or any other unit testing frameworks.
Cheers.