1
votes

I am trying to implement unit testing with yii. I go to the protected\tests\unit folder and run phpunit\AccountTest

I get the error Class 'CDbTestCase' not found in ......tests\unit\AccountTest.php

I am new to unit testing and I am not sure if I set it up properly. Can someone tell me what I did wrong?

1

1 Answers

2
votes

This can happen if your bootstrap.php script has incorrect paths in it.

Your protected/tests/bootstrap.php file should look like this:

<?php

// change the following paths if necessary
$yiit=dirname(__FILE__).'/../../../framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';

require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');

Yii::createWebApplication($config);

Notice lines 4-5. The paths will vary based on how you installed Yii and your app. Look at the locations of your files, and make sure those paths point to the correct places.

I'd also recommend running PHPUnit from inside protected/tests, not protected/tests/unit. e.g.:

cd protected\tests
phpunit unit\AccountTest.php

PHPUnit sometimes won't bootstrap correctly if run from inside the unit folder.