Skip to content

Commit

Permalink
add asssertion for session errors
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 15, 2017
1 parent 3614cfb commit dbaf3b1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ public function assertSessionHasAll(array $bindings)
return $this;
}

/**
* Assert that the session has the given errors.
*
* @param string|array $keys
* @param mixed $format
* @return $this
*/
public function assertSessionHasErrors($keys = [], $format = null)
{
$this->assertSessionHas('errors');

$keys = (array) $keys;

$errors = app('session.store')->get('errors');

foreach ($keys as $key => $value) {
if (is_int($key)) {
PHPUnit::assertTrue($errors->has($value), "Session missing error: $value");
} else {
PHPUnit::assertContains($value, $errors->get($key, $format));
}
}

return $this;
}

/**
* Assert that the session does not have a given key.
*
Expand Down

0 comments on commit dbaf3b1

Please sign in to comment.