Skip to content

Commit

Permalink
Assert that the session contains a given piece of data using a closure
Browse files Browse the repository at this point in the history
Just like `$response->assertViewHas()` accepts a closure as a second parameter which is called to evaluate the contents of the view data, `$response->assertSessionHas()` could implement a similar behavior.
  • Loading branch information
sebdesign committed Jun 13, 2019
1 parent 02d2422 commit 730488e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ public function assertSessionHas($key, $value = null)
$this->session()->has($key),
"Session is missing expected key [{$key}]."
);
} elseif ($value instanceof Closure) {
PHPUnit::assertTrue($value($this->session()->get($key)));
} else {
PHPUnit::assertEquals($value, $this->session()->get($key));
}
Expand Down

0 comments on commit 730488e

Please sign in to comment.