phpunit-testingcakephpcakephp-3.0fixture

CakePHP 3.x - fixtures import does not load data


I am trying to import fixtures in my CakePHP 3.x plugin. When I launch the tests, I always get the error :

UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile exception 'Cake\Datasource\Exception\RecordNotFoundException' with message 'Record not found in table "users"

Here is UsersFixture.php :

namespace UserManager\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;

class UsersFixture extends TestFixture {
    public $import = ['table' => 'users'];
}

My test fails because it can not find the current user in test database.

I supposed that users table is created successfully, but no data are imported.

Of course, many users are recorded in my existing users table, and the tested user id is one of these records.

My testIndex() method fails too, because number of records is always equal to 0.

Why does the fixtures table not contain my records ?


Solution

  • Unfortunately, I think there's nothing wrong with your code. From what I can see, CakePHP 3.x does not support the importation of table entries in the fixtures anymore, only the table structure.

    (See doc differences: 2.x: Importing table information and records, 3.x: Importing table information)

    I don't think there's any way around it, unless you modify CakePHP 3.x core directly.