我的产品工厂包含一个slu ::
$factory->define(Product::class, function (Faker $faker) {
return [
'title' => $faker->sentence(4, true),
'slug' => $faker->slug,
'description' => $faker->paragraph,
];
});
我的功能测试使用工厂制作新实例:
$product = factory(Product::class)->make();
$response = $this->post('admin/products/store', $product->toArray());
$editPage = $this->get($response->headers->get('Location'));
$editPage->assertSeeText($product->title);
当我运行测试时,我收到一条SQL错误,指出slug缺失:
Error creating product:SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: products.slug (SQL: insert into "products" ("title", "description", "updated_at", "created_at") values (Velit quisquam et accusamus debitis et., Aperiam sint architecto ut sit pariatur aliquid. Et et omnis perspiciatis. Est officiis accusamus enim ut rerum cumque., 2018-02-05 23:58:02, 2018-02-05 23:58:02))
同样的方法适用于我的其他功能测试。测试将作为经过身份验证的管理员运行所有必要的权限。
答案 0 :(得分:1)
我无法评论,因为我没有50点声望! 我只是想知道你是否在产品模型中做了可填写的东西
protected $fillable = ['slug'];