我正在对我的应用程序进行测试,并且已经到了需要测试控制器的销毁方法的地步。我目前的测试是:
public function test_user_can_delete_draft()
{
$user = factory(User::class)->states('confirmed', 'normaluser')->create();
$userForm = factory(Form::class)->states('in_house_signs')->create(['user_id' => $user->id, 'status' => 'draft',]);
// Test creator can delete form
$response = $this->actingAs($user)->delete(route('forms.destroy', $userForm));
$response->assertSuccessful();
}
我正在测试的控制器中的方法是:
public function destroy($id) {
$form = Form::find($id);
Comment::where('form_id', $id)->delete();
$form->delete();
// Redirect
return redirect()->back()->with('status', 'Form successfully deleted');
}
当我运行 phpunit 时,我收到错误:
Response status code [302] is not a successful status code.
Failed asserting that false is true.
我应该怎么做才能让测试正常运行?