我收到錯誤,如下面失敗斷言1場比賽在laravel測試預計0
Found unexpected records in database table [customers] that matched attributes [{"id":89}]. Failed asserting that 1 matches expected 0.
CustomerTest.php:
public function testDestroyCustomer()
{
// $this->assertTrue(true);
$post = factory(Customer::class,1)->create();
$this->delete(route('customer.destroy', $post->id));
$this->assertResponseStatus(500);
$this->dontSeeInDatabase('customers', ['id' => $post->id]);
}
routes.php文件
Route::resource('customer', 'CustomerController', [
'names' => [
'index' => 'customer'
]
]);
CustomerController中的銷燬功能:
public function destroy($id)
{
$delete = Customer::where('id',$id)->delete();
}
我該如何解決錯誤?任何建議,請。
在哪裏查詢可能返回集合,試圖在where子句後第()鏈接,或者使用find()來代替。 – Wreigh
@WreighChristianSantos:我已經嘗試了兩個仍然錯誤仍然存在。任何想法 ? – 06011991
應該只爲索引聲明路由名稱嗎?我對此並不熟悉,因爲我不使用這種格式的名稱。無論如何,我認爲如果無法找到路線摧毀,它應該拋出404對嗎? – Wreigh