0

The Illuminate\Testing\TestResponse::assertSessionHasNoErrors() isn't working as I would expect it to.

I have something like this in my code:

$response = $this->post('account/project/create', $array);

$response->assertStatus(200); // FAILS
$response->assertStatus(500); // PASSES
$response->assertSessionHasErrors(); // FAILS
$response->assertSessionHasNoErrors(); // PASSES

As you can see, the POST returns a 500, but assertSessionHasErrors does not fail. I would expect it to fail and return the exception message. I do not want to skip over exceptions by using $this->withoutExceptionHandling().

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
iateadonut
  • 1,951
  • 21
  • 32

1 Answers1

0

Shortly after I posted this, I read that assertSessionHasErrors is only for validation errors. I use it often in unit tests so the change confused me a little.

For feature tests, you should just use $response->assertStatus(200) or $response->assertSuccesfull() and then you'll be given a stack trace if there is an exception.

This is pretty obvious, but I decided to leave my question up as I've been banging my head against the wall about it for more than an hour. I did not want to skip over exceptions by using $this->withoutExceptionHandling().

iateadonut
  • 1,951
  • 21
  • 32