在laravel测试中声明1与预期的0匹配失败

时间:2017-06-27 07:31:37

标签: unit-testing laravel-5.4

我收到如下错误

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();
    }

如何解决错误?任何建议请。

1 个答案:

答案 0 :(得分:0)

我认为您的删除路由应该是,

变化:

route('customer.destroy', $post->id);route('customer.destroy', ['id' => $post->id]);