problem with CDbFixtureManager

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



My test.php config file is set up like this…




return CMap::mergeArray(

	require(dirname(__FILE__).'/main.php'),

	array(

		'components'=>array(

			'fixture'=>array(

				'class'=>'system.test.CDbFixtureManager',

				'connectionID'=>'db',

			),

			'db'=>array(

				'connectionString' => 'mysql:host=localhost;dbname=mydb',

				'emulatePrepare' => true,

				'username' => '[user]',

				'password' => '[password]',

				'charset' => 'utf8',

			),

		),

	)

);




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?

show your testcase script?

Here’s a sample test class…




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.




bump.

Any suggestions?

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:


require_once(Yii::getPathOfAlias('application.models.User').'.php');

(Would probably be "Users" in your case.)

/Tommy

Thanks for the suggestion but it made no difference I’m afraid. The weird thing is the same project in my Ubuntu set up doesn’t throw the error.

Have you ensured that your test config is, indeed, being loaded? I.e. make sure that protected/tests/bootstrap.php has the correct config file loaded:




$config=dirname(__FILE__).'/../config/test.php';

Seems like maybe the "fixture" component is not being found in the loaded configuration.

Yep I just checked the test.php configuration file gets called and it does.

Did you send up resolving your issue?

One thing to do is to try loading the interactive shell with the test config. So, from the root of your Web app:


% YiiRoot/framework/yiic shell protected/config/test.php


Yii Interactive Tool ...

Please type 'help' for help. Type 'exit' to quit.

>>

then try:




>>print_r(Yii::app()->getComponent('fixture'));

and verify you get back a CDbFixtureManager Object

@jefftulsa Sorted!

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.

Thanks for your help on this.