PHPUnit / Yii Blog / Windows/ Post Model not found


I am starting with PHPUnit. I have installed PHPUnit 3.6.12 on Windows/XAMPP.

I’d like to run the tests supplied with the blog demo as described in the Yii guide.

I am in C:\xampp\htdocs\…\blog\protected\tests.

phpunit -h

works (added C:\xampp\php to PATH).

phpunit unit

doesn’t work:

PHPUnit 3.6.12 by Sebastian Bergmann.

Configuration read from C:\xampp\htdocs\test\yii\blog\protected\tests\phpunit.xml

Fatal error: Class 'Post' not found in C:\Frameworks\yii-git\framework\db\ar\CActiveRecord.php on line 382

Call Stack:

	0.0010 	329360   1. {main}() C:\xampp\php\phpunit:0

	0.0562 	774800   2. PHPUnit_TextUI_Command::main() C:\xampp\php\phpunit:46

	0.0563 	775216   3. PHPUnit_TextUI_Command->run() C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:130

	0.5258	5644576   4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:192

	0.5368	6013296   5. PHPUnit_Framework_TestSuite->run() C:\xampp\php\PEAR\PHPUnit\TextUI\TestRunner.php:325

	0.5370	6013784   6. PHPUnit_Framework_TestSuite->run() C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:705

	0.5373	6014064   7. PHPUnit_Framework_TestSuite->runTest() C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:745

	0.5373	6014064   8. PHPUnit_Framework_TestCase->run() C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:772

	0.5375	6014064   9. PHPUnit_Framework_TestResult->run() C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:751

	0.5618	6074696  10. PHPUnit_Framework_TestCase->runBare() C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php:649

	0.5661	6255208  11. CDbTestCase->setUp() C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:801

	0.6712	7510088  12. CDbFixtureManager->load() C:\Frameworks\yii-git\framework\test\CDbTestCase.php:118

	0.6799	8264240  13. CActiveRecord::model() C:\Frameworks\yii-git\framework\test\CDbFixtureManager.php:301

Any ideas appreciated where to start looking at…

Best regards,


Is your bootstrap.php file loaded correctly?

It seems that your Post model is not loaded. Maybe that’s because the module or model is not loaded in your test config file. Do you merge your test config file with your main config file in /protected/config/test.php?

Do you import all models via “application.models.*” in your test.php import definition? The autoloader won’t find the classes otherwise


this is the bootstarp.php file:


// change the following paths if necessary







This is the output from protected/config/test.php:

array(7) {


  string(49) "C:\xampp\htdocs\test\yii\blog\protected\config\.."


  string(13) "Yii Blog Demo"


  array(1) {


	string(3) "log"



  array(2) {


	string(20) "application.models.*"


	string(24) "application.components.*"



  string(4) "post"


  array(6) {


	array(1) {





	array(2) {


  	string(74) "sqlite:C:\xampp\htdocs\test\yii\blog\protected\config/../data/blog-test.db"


  	string(4) "tbl_"



	array(1) {


  	string(10) "site/error"



	array(2) {


  	string(4) "path"


  	array(3) {


    	string(9) "post/view"


    	string(10) "post/index"


    	string(21) "<controller>/<action>"




	array(2) {


  	string(10) "CLogRouter"


  	array(1) {


    	array(2) {


      	string(13) "CFileLogRoute"


      	string(14) "error, warning"





	array(1) {


  	string(29) "system.test.CDbFixtureManager"




  array(7) {


	string(11) "My Yii Blog"


	string(21) ""










	string(36) "Copyright &copy; 2009 by My Company."



So it appears that application.models.* should be loaded ?!



You could add the Post model manually via Yii::import(“application.models.Post”) in your test file. Then you’ll at least know what’s wrong

That worked!

I added


in unit/PostTest.php and similar in all other unit/*Test.php files.

But anyways, there must be something wrong with my setup that I need to explicitly add the import ?!