3

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 ?

2 Answers 2

9

You can certainly import records in cake 3.

From cake bake bin/cake bake fixture invoice_statuses -r --count 100 You would need to regenerate this every time you make changes to the table but it is better than nothing. Gives you a nice starting point.

You can also use conditions to generate very specific fixtures.

enter image description here

1
4

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.

1
  • Great thanks to you ! I think 3.x french translation contains mistakes, speaking of "Importer les informations de table et les enregistrements".
    – iamsaloc
    Jun 1, 2015 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.