问题
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 ?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/30434431/cakephp-3-x-fixtures-import-does-not-load-data