Im currently trying to view my sql queries in some kind of log, and it doesn’t seem to be working with the CLogRoute. I have profiling enabled, but I want to see the actual queries that are being run, as one of my models is acting strange. Here is my test.php config file:
well I have the YII_DEBUG set in that test.php config file, and since Im just running unit tests, it will never load the index.php file. I changed my testing bootstrap file to have the YII_DEBUG constant, but I’m still not getting any output anywhere.
Could you try with CWebLogRoute first (with default parameters, no level, categories, etc.)? It’s the quickest way to see logs. They get added right at the end of your page. Just to make sure, you don’t have a permission problem…
yeah the weblogroute doesn’t show any output when using phpunit to test models, which is what I am trying to get, it will show output when going through HTTP, which is not what I need. Surely I can’t be the first person to have needed this haha
Ok so I kind of got this working, I think it has something to do with triggering the clean up endRequest event from yii.
if in my phpunit CDbTestCase function I want to see all the sql that was used during that particular run then I had to call this:
for me, at least according my config (above) it will create a file called sql.log in runtime/. It prints out a bunch of stuff, but it has helped me figure out a few things when debugging active record queries.
I had the same problem now. I missed in your first post, that you talked about test cases . Your hint with processLogs() brought me on the right track: The OnEndRequest is not fired after each test. So i added this to all my testcases:
public static $isIsolated=false;
// We need to do that, to access isolation status from static tearDownAfterClass:
public function setUp()
public function tearDown()
if (self::$isIsolated) // Each test requires a onEndRequest
public static function tearDownAfterClass()
if (!self::$isIsolated) // OnEndRequest is triggered after last test
Now you your logfiles will be populated again.
EDIT: And since IPB board is crap, you have to manually make an uppercase "E" from onEndRequest…