CakePHP 3.x - 固定装置导入不加载数据
CakePHP 3.x - fixtures import does not load data
我正在尝试在我的 CakePHP 3.x 插件中导入固定装置。
当我启动测试时,我总是收到错误消息:
UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile
exception 'Cake\Datasource\Exception\RecordNotFoundException' with message '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'];
}
我的测试失败了,因为在测试数据库中找不到当前用户。
我以为用户 table 创建成功,但没有导入数据。
当然,我现有的用户table里面记录了很多用户,测试的用户id就是这些记录之一。
我的 testIndex() 方法也失败了,因为记录数总是等于 0。
为什么灯具 table 不包含我的记录?
不幸的是,我认为您的代码没有任何问题。据我所知,CakePHP 3.x 不 不再支持在固定装置中导入 table 条目,仅支持 table 结构。
(参见文档差异:2.x:Importing table information and records, 3.x: Importing table information)
我认为没有任何解决办法,除非您直接修改 CakePHP 3.x 核心。
蛋糕3中当然可以导入记录了
来自烘焙蛋糕bin/cake bake fixture invoice_statuses -r --count 100
每次对 table 进行更改时都需要重新生成它,但这总比没有好。给你一个很好的起点。
您还可以使用条件来生成非常具体的固定装置。
我正在尝试在我的 CakePHP 3.x 插件中导入固定装置。 当我启动测试时,我总是收到错误消息:
UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile exception 'Cake\Datasource\Exception\RecordNotFoundException' with message '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'];
}
我的测试失败了,因为在测试数据库中找不到当前用户。
我以为用户 table 创建成功,但没有导入数据。
当然,我现有的用户table里面记录了很多用户,测试的用户id就是这些记录之一。
我的 testIndex() 方法也失败了,因为记录数总是等于 0。
为什么灯具 table 不包含我的记录?
不幸的是,我认为您的代码没有任何问题。据我所知,CakePHP 3.x 不 不再支持在固定装置中导入 table 条目,仅支持 table 结构。
(参见文档差异:2.x:Importing table information and records, 3.x: Importing table information)
我认为没有任何解决办法,除非您直接修改 CakePHP 3.x 核心。
蛋糕3中当然可以导入记录了
来自烘焙蛋糕bin/cake bake fixture invoice_statuses -r --count 100
每次对 table 进行更改时都需要重新生成它,但这总比没有好。给你一个很好的起点。
您还可以使用条件来生成非常具体的固定装置。