Information and Communications Technology

Yii Console Log with Unit Testing

1. install phpunit correctly
pear install phpunit/PHPUnit
pear install phpunit/PHPUnit_Selenium
2. create the class CConsoleLogRoute in the components directory in the file CConsoleLogRoute.php with this code:
class CConsoleLogRoute extends CLogRoute {
protected function processLogs($logs)
foreach($logs as $log) {
echo $this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
3. configure YII to log when unit testing:
3a. add the log key in the components array in protected/config/test.php
‘levels’=>’error, warning, info, trace’,
3b. add some lines in protected/tests/bootstrap.php, the modified file should be this: (added the lines with YII_DEBUG, YII_TRACE_LEVEL, autoFlush and autoDump)
// change the following paths if necessary
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);
defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’, 0);
Yii::getLogger()->autoFlush = 1;
Yii::getLogger()->autoDump = true;