CakePHP 3.x-夹具导入不会加载数据 [英] CakePHP 3.x - fixtures import does not load data

查看:74
本文介绍了CakePHP 3.x-夹具导入不会加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CakePHP 3.x插件中导入灯具。
启动测试时,总是出现错误:

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
异常'Cake\Datasource\Exception\RecordNotFoundException',消息为在用户表中找不到记录

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

这里是UsersFixture.php:

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.

我认为users表创建成功,但是没有数据导入。

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

当然,许多用户都记录在我的现有用户表中,而经过测试的用户ID就是这些记录之一。

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

我的testIndex()方法也失败了,因为记录数始终等于0。

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

为什么夹具表不包含我的记录?

Why does the fixtures table not contain my records ?

推荐答案

不幸的是,我认为您的代码没有错。据我所知,CakePHP 3.x不再不再支持在固定装置中导入表项,仅支持表结构。

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.

(请参阅文档差异:2.x:导入表信息和记录 ,3.x:导入表格信息

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

我不除非您直接修改CakePHP 3.x内核,否则您认为有任何解决方法。

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

这篇关于CakePHP 3.x-夹具导入不会加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆