Yii Framework Forum: Logging Inside PHPUnit Test Cases - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Logging Inside PHPUnit Test Cases Rate Topic: ***** 1 Votes

#1 User is offline   David George 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-October 09

Posted 30 October 2009 - 07:16 AM

Hi all,

I'm working on a site with yii, which is very nice and everything is fine except the logging doesn't work when I run my test cases. I'm basically logging values inside my model classes which works when I run the application in the browser fine. My tests are supported by a bootstrapper and the models are run inside unit tests as usual.

The unit tests run fine, but they don't add anything to the logs. Is there anything I need to do to like activate the logger in the bootstrapper?

Here's my bootstrapper: -
<?php
  $yiit = '/usr/share/php/yii-framework/framework/yii.php';
  $config= dirname(__FILE__) . '/../config/test.php';

  require_once($yiit);	
  Yii::createWebApplication($config);


Here's my test config snippet: -
'log'=>array(
  'class'=>'CLogRouter',
  'routes'=>array(
    array(
      'class'=>'CFileLogRoute',
      'levels'=>'error, warning, info, trace',
      'filter'=>'CLogFilter',
      'categories' => 'system.*'
    ),
  ),
),


Here's how I'm logging my messages: -
Yii::log('example message', 'info', 'bobcom');


thanks for any help
David
0

#2 User is offline   thaddeusmt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 14-October 09
  • Location:Utah

Posted 03 December 2009 - 01:35 PM

I would like to figure out how to do this too, have you had any luck? I'll let you know if I get anywhere.
0

#3 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 03 December 2009 - 02:33 PM

Hi

Looks like your logger is monitoring the category "system.*" and the log you are testing with specifies "bobcom" as the category to log to. Since they do not match you will not the event. See the document here http://www.yiiframew.../topics.logging

nZ
0

#4 User is offline   atom_747 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-October 10

Posted 05 October 2010 - 09:23 AM

Hi,

Had the same problem...

Saw that qiang recommended to register a shutdown function here (http://www.yiiframew...d-does-not-log/)


So I added to the bootstrap.php

function shutdown() {
Yii::app()->end();
}

register_shutdown_function('shutdown');

cheers,
atom
3

#5 User is offline   JeffM 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-February 11

Posted 10 March 2011 - 01:44 AM

Another helpful hint:

To see the tracing done by other parts of Yii, i.e., the Yii::trace calls, (for me the CActiveRecord SQL calls were particularly helpful) in unit tests, one needs to enable DEBUG mode in the unit tests, just as it is enabled in the index.php file.

I copied this fragment from index.php:

defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 1);


to protected/tests/bootstrap.php

Then I can see the SQL generated by my overridden CActiveRecord methods.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users