CakePHP test fixture to use different table name

1.6k Views Asked by At

I got a model which is defined with

class User extends AppModel{
    public $useTable = 'members';
    ....
    ....

which works fine, now I want to use a fixture for a unit test on this model.

I define the fixture as so

App::uses('User', 'Model');

class UserFixture extends CakeTestFixture {
    public $useTable = 'members';

    public $import = array('table' => 'members');
    ....
    ....

however the table it creates is called cake_users NOT cake_members - which then causes the test and controller and other code to fail since it can't find cake_members.

How can I get the fixture the test db as cake_members

This is the error

Table cake_members for model User was not found in datasource test.

This is using cake 2.2.1

1

There are 1 best solutions below

0
On

Changed

$useTable = "members";

to

$table = 'members';

in the fixture, as suggested here

http://www.pixelastic.com/blog/193:using-a-fixture-with-a-model-using-usetable-in-cakephp