I'm testing saving data into the database. When missing required fields I throw an exception and then redirect from my controller:
try {
$product = Product::create([
'name' => $request->name,
'description' => $request->description,
]);
return redirect('home')->with('success', 'Record has been added');
} catch(\Exception $e) {
return redirect()->to('course/create')
->withInput($request->input())
->with('errors', 'Required Fields Not Submitted');
}
I wanna test the redirect, whether the session has errors and whether the initial data passed is returned in order to populate the form, so in my unit test I have:
$response = $this->post("/courses/", $data);
$response->assertRedirect('/courses/create');
$response->assertSessionHasErrors();
//$response->assertSessionHasAll();
$response->assertHasOldInput();
but when hitting assertSessionHasErrors I'm getting:
Error: Call to a member function getBag() on string
and when hitting assertHasOldInput I'm getting:
BadMethodCallException: Call to undefined method Illuminate\Http\RedirectResponse::assertHasOldInput()
what seems to be the issue?
Thanks.