I have a problem with CDbFixtureManager that is causing issues running tests. On a windows machine using xampp, I run into this problem when running tests on a class that requires fixtures;
C:\xampp\htdocs\example.com\protected\tests>phpunit unit\UHControllerTest.php
PHPUnit 3.4.9 by Sebastian Bergmann.
E
Fatal error: Call to a member function load() on a non-object in C:\xampp\frameworks\yii\1.1.4\framework\test\CDbTestCase.php on line 117
Call Stack:
0.0003 329312 1. {main}() C:\xampp\php\PEAR\PHPUnit\phpunit:0
0.0917 5095080 2. PHPUnit_TextUI_Command::main() C:\xampp\php\PEAR\PHPUnit\phpunit:54
0.0917 5095432 3. PHPUnit_TextUI_Command->run() C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:146
0.1341 7499960 4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\PEAR\PHPUnit\TextUI\Command.php:213
0.1361 7506024 5. PHPUnit_Framework_TestSuite->run() C:\xampp\php\PEAR\PHPUnit\TextUI\TestRunner.php:349
0.1459 7945800 6. PHPUnit_Framework_TestSuite->runTest() C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:731
0.1459 7945800 7. PHPUnit_Framework_TestCase->run() C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php:756
0.1460 7945800 8. PHPUnit_Framework_TestResult->run() C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:652
0.1461 7946384 9. PHPUnit_Framework_TestCase->runBare() C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php:686
0.1464 7959816 10. UHControllerTest->setUp() C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php:700
0.1464 7959816 11. CDbTestCase->setUp() C:\xampp\htdocs\example.com\protected\tests\unit\UHControllerTest.php:33
I’ve tried debugging and it appears that getFixtureManager() in CDbTestCase::setUp returns null where is should be an instance of CDbFixtureManager. However this is as far as I have got and not sure how to fix from here. Any suggestions?
class UHControllerTest extends CDbTestCase
{
/**
* The SOAP client
* @var object
*/
protected $client;
/**
* The API key
* @var string
*/
protected $apiKey = '';
/**
* The SOAP URL
* @var string $url
*/
public $url = 'http://api.example.com/uh.soap';
public $fixtures = array(
'users'=>'Users'
);
/**
* Set the SOAP client object
*/
public function setUp()
{
parent::setUp();
$this->client = new SoapClient($this->url);
}
/**
* Test the soap object is set up correctly
*/
public function testSetUp()
{
$this->assertTrue($this->client instanceof SoapClient);
$this->assertType('string',$this->url);
}
/**
* Tests for valid SOAP response
*/
public function testApiTest()
{
$this->assertType('string',$this->client->apiTest());
$this->assertEquals('API connection success',$this->client->apiTest());
}
//.. more test cases etc.
Don’t ask me why it’s required (given that the standard configuration is merged with the test config), but I use this to make models available in the test script:
It turned out to be the connection details to the database that were incorrect. Loading up the shell using the test.php config file provided better error messages that highlighted the issue correctly.