Usage of fixtures with modules

Hello,

I’m developing selenium tests for my application built with Yii 1.1.3 framework.

I use some modules located in protected/modules directory.

All worked fine, until I tried to use fixtures.

It seems to work well with models in protected/models, but not with those in protected/modules/*/models.

For a "user" module, I put a User.php in fixtures directory and I tried several solutions :


	public $fixtures=array(

		'user'=>'User',

	);

As a result, I had :

include(User.php): failed to open stream: No such file or directory

With :


	public $fixtures=array(

		'user'=>'user.models.User',

	);

No error, table is reseted, but data in fixtures/User.php are not loaded (and of course tests failed).

Generally speaking, what is the recommended strategy to test a site and its modules ?

Put all tests in protected/tests directory (My choice, but I use subdirectories to catalog my tests) ?

Create some tests directory in each module ?

Any advice is welcomed !

I think the problem comes from table prefix.

My User model is in modules/user/models/User.php, but my table is named dbprefix_user.

Table prefix is set in main.php, but is not taken into account for fixtures.

Files in fixtures directory must be named dbprefix_name.php.

Seems to be a kind of bug for me.

Can anyone confirm before I open a ticket?

Same problem here. And I think this is a bug. In my point of view, if I’m publishing the system in a shared host environment and I have table prefixes I will need to rename the whole set of files for the fixtures to be loaded in the environment.

I have a problem testing my modules too. Somehow I felt that testing in Yii framework is somewhat difficult and unencouraged. I place fixtures and unit test scripts under my module in a ‘tests’, and ‘tests/fixtures’ folder, which is the same structure with ‘protected/tests’. I run phpunit inside my modules tests folder, but the fixtures doesn’t want to load. Anybody can help me?

By default, fixtures are in ‘application.tests.fixtures’, except if you overwrite CDbFixtureManager::$basePath.

There is an example at Different fixtures for different test cases.