【问题标题】:CakePHP 3.x - fixtures import does not load dataCakePHP 3.x - 夹具导入不加载数据
【发布时间】:2015-08-06 16:53:26
【问题描述】:

我正在尝试在我的 CakePHP 3.x 插件中导入固定装置。 当我启动测试时,我总是得到错误:

UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile 异常 'Cake\Datasource\Exception\RecordNotFoundException' 带有消息 'Record not found in table "users"

这里是 UsersFixture.php :

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

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

我的测试失败,因为它在测试数据库中找不到当前用户。

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

当然,我现有的users表中记录了很多用户,测试的用户id就是这些记录之一。

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

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

【问题讨论】:

    标签: php unit-testing cakephp cakephp-3.0 fixture


    【解决方案1】:

    你当然可以在 cake 3 中导入记录。

    来自蛋糕烘焙bin/cake bake fixture invoice_statuses -r --count 100 每次对表进行更改时都需要重新生成它,但总比没有好。为您提供一个很好的起点。

    您还可以使用条件来生成非常具体的夹具。

    【讨论】:

    【解决方案2】:

    很遗憾,我认为您的代码没有任何问题。从我所见,CakePHP 3.x 确实不再支持在固定装置中导入表条目,只支持表结构。

    (参见文档差异:2.x:Importing table information and records,3.x:Importing table information

    我认为没有办法解决,除非你直接修改 CakePHP 3.x 核心。

    【讨论】:

    • 非常感谢您!我认为3.x法文翻译有错误,说到“Importer les informations de table et les enregistrements”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2011-06-07
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多