jwerner
(Joachim Werner)
August 31, 2012, 8:07am
1
Hello,
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,
Joachim
sjakie
(Arjanwestdorp)
August 31, 2012, 8:34am
2
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?
Haensel
(Johannes)
August 31, 2012, 8:35am
3
Do you import all models via “application.models.*” in your test.php import definition? The autoloader won’t find the classes otherwise
jwerner
(Joachim Werner)
August 31, 2012, 9:06am
4
Hi,
this is the bootstarp.php file:
<?php
// change the following paths if necessary
//$yiit=dirname(__FILE__).'/../../../../framework/yiit.php';
$yiit='C:/Frameworks/yii-git/framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';
require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');
Yii::createWebApplication($config);
This is the output from protected/config/test.php:
array(7) {
["basePath"]=>
string(49) "C:\xampp\htdocs\test\yii\blog\protected\config\.."
["name"]=>
string(13) "Yii Blog Demo"
["preload"]=>
array(1) {
[0]=>
string(3) "log"
}
["import"]=>
array(2) {
[0]=>
string(20) "application.models.*"
[1]=>
string(24) "application.components.*"
}
["defaultController"]=>
string(4) "post"
["components"]=>
array(6) {
["user"]=>
array(1) {
["allowAutoLogin"]=>
bool(true)
}
["db"]=>
array(2) {
["connectionString"]=>
string(74) "sqlite:C:\xampp\htdocs\test\yii\blog\protected\config/../data/blog-test.db"
["tablePrefix"]=>
string(4) "tbl_"
}
["errorHandler"]=>
array(1) {
["errorAction"]=>
string(10) "site/error"
}
["urlManager"]=>
array(2) {
["urlFormat"]=>
string(4) "path"
["rules"]=>
array(3) {
["post/<id:\d+>/<title:.*?>"]=>
string(9) "post/view"
["posts/<tag:.*?>"]=>
string(10) "post/index"
["<controller:\w+>/<action:\w+>"]=>
string(21) "<controller>/<action>"
}
}
["log"]=>
array(2) {
["class"]=>
string(10) "CLogRouter"
["routes"]=>
array(1) {
[0]=>
array(2) {
["class"]=>
string(13) "CFileLogRoute"
["levels"]=>
string(14) "error, warning"
}
}
}
["fixture"]=>
array(1) {
["class"]=>
string(29) "system.test.CDbFixtureManager"
}
}
["params"]=>
array(7) {
["title"]=>
string(11) "My Yii Blog"
["adminEmail"]=>
string(21) "webmaster@example.com"
["postsPerPage"]=>
int(10)
["recentCommentCount"]=>
int(10)
["tagCloudCount"]=>
int(20)
["commentNeedApproval"]=>
bool(true)
["copyrightInfo"]=>
string(36) "Copyright © 2009 by My Company."
}
}
So it appears that application.models.* should be loaded ?!
Thanks,
Joachim
Haensel
(Johannes)
August 31, 2012, 10:22am
5
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
jwerner
(Joachim Werner)
August 31, 2012, 10:47am
6
That worked!
I added
Yii::import("application.models.Post");
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 ?!
Thanks,
Joachim