Bala
Bala

Reputation: 61

Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse"

Controller code:

return redirect()->route('admin.patient.edit', $patientId);

Test code:

$this->visit(route('admin.patient.edit', $this->patient->id))
     ->press('Update');

$this->assertRedirectedToRoute('admin.patient.edit', [$this->patient->id]);

The error I get is this:

Failed asserting that Illuminate\Http\Response Object (...) is an instance of class 
"Illuminate\Http\RedirectResponse".

I've printed out the response from the inside the test and inside the controller and it is in fact a RedirectReponse Object. Any ideas?

Upvotes: 4

Views: 1931

Answers (1)

Adrien C
Adrien C

Reputation: 424

As mercuryseries stated here https://stackoverflow.com/a/38341866/3005056, the visit method might not be what you are looking for since it follows redirection.

"A simple way is to use the get method instead of visit.

An example:

$this->get('/facebook')
     ->assertRedirectedTo('https://www.facebook.com/Les-Teachers-du-NET-516952535045054');"

Upvotes: 2

Related Questions