Skip to content

Commit 2dcbcec

Browse files
authored
Update assertSessionMissing to allow checking for specific value (#55763)
1 parent a720cbe commit 2dcbcec

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,19 +1640,26 @@ public function assertSessionHasErrorsIn($errorBag, $keys = [], $format = null)
16401640
* Assert that the session does not have a given key.
16411641
*
16421642
* @param string|array $key
1643+
* @param mixed $value
16431644
* @return $this
16441645
*/
1645-
public function assertSessionMissing($key)
1646+
public function assertSessionMissing($key, $value = null)
16461647
{
16471648
if (is_array($key)) {
16481649
foreach ($key as $value) {
16491650
$this->assertSessionMissing($value);
16501651
}
1651-
} else {
1652+
}
1653+
1654+
if (is_null($value)) {
16521655
PHPUnit::withResponse($this)->assertFalse(
16531656
$this->session()->has($key),
16541657
"Session has unexpected key [{$key}]."
16551658
);
1659+
} elseif ($value instanceof Closure) {
1660+
PHPUnit::withResponse($this)->assertTrue($value($this->session()->get($key)));
1661+
} else {
1662+
PHPUnit::withResponse($this)->assertEquals($value, $this->session()->get($key));
16561663
}
16571664

16581665
return $this;

tests/Testing/TestResponseTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,18 @@ public function testAssertSessionMissing()
28072807
$response->assertSessionMissing('foo');
28082808
}
28092809

2810+
public function testAssertSessionMissingValue()
2811+
{
2812+
$this->expectException(AssertionFailedError::class);
2813+
2814+
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));
2815+
2816+
$store->put('foo', 'goodvalue');
2817+
2818+
$response = TestResponse::fromBaseResponse(new Response());
2819+
$response->assertSessionMissing('foo', 'badvalue');
2820+
}
2821+
28102822
public function testAssertSessionHasInput()
28112823
{
28122824
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));

0 commit comments

Comments
 (0)