about fixtrue test errors

I create fixture test as follow:

1:create fixture file

1)add a new file in tests/fixtures/tbl_project.php

2)add an array to it:




return array(

    'project1' => array(

        'name' => 'Test Project 1',

        'description' => 'This is test project 1',

        'create_time' => '',

        'create_user_id' => '',

        'update_time' => '',

        'update_user_id' => '',

    ),

)

...



3)and I configure config/test.php




return CMap::mergeArray(

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

	array(

		'components'=>array(

			'fixture'=>array(

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

			),

			/* uncomment the following to provide test database connection

			'db'=>array(

				'connectionString'=>'DSN for test database',

			),

			*/

                        'db'=>array(

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

                                'emulatePrepare' => true,

                                'username' => 'root',

                                'password' => '********',

                                'charset' => 'utf8',

                        ),

		),

	)

);



4):declear in my ProjectTest.php




class ProjectTest extends CDbTestCase{ 


    public $fixtures = array(

                        'projects' => 'Project',

        );

}



but I use phpunit to test a assert :




$this->assertTrue($this->projects('project1') instanceof Project);



the phpunit output like:

  1. ProjectTest::testCreate

Invalid argument supplied for foreach()

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:168

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:122

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:85

D:\xampp\xampp\htdocs\yii6\framework\base\CModule.php:372

D:\xampp\xampp\htdocs\yii6\framework\test\CDbTestCase.php:84

D:\xampp\xampp\htdocs\yii6\framework\test\CDbTestCase.php:116

why ?




class ProjectTest extends CDbTestCase{ 


    public $fixtures = array(

                        'projects' => 'Project',

        );

}



I think ‘projects’ needs to match your fixture file name wich in turn needs to match your database table.

but I change the code like these:

table name and fixtures key are the same: tbl_project




    public $fixtures = array(

                        'tbl_project' => 'Project',

        );

    public function testFixture(){

        var_dump($this->tbl_project);

    }



the error is like:

D:\xampp\xampp\htdocs\trackstar\protected\tests>phpunit unit

PHPUnit 3.5.13 by Sebastian Bergmann.

…E

Time: 1 second, Memory: 8.50Mb

There was 1 error:

  1. ProjectTest::testFixture

Invalid argument supplied for foreach()

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:168

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:122

D:\xampp\xampp\htdocs\yii6\framework\test\CDbFixtureManager.php:85

D:\xampp\xampp\htdocs\yii6\framework\base\CModule.php:372

D:\xampp\xampp\htdocs\yii6\framework\test\CDbTestCase.php:84

D:\xampp\xampp\htdocs\yii6\framework\test\CDbTestCase.php:116

FAILURES!

Tests: 5, Assertions: 10, Errors: 1.