Skip to content

Commit e0b7d84

Browse files
barclaymichaeltegos
authored andcommitted
Fix session value is missing assertion (laravel#57134)
1 parent 7172181 commit e0b7d84

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,9 @@ public function assertSessionMissing($key, $value = null)
17111711
"Session has unexpected key [{$key}]."
17121712
);
17131713
} elseif ($value instanceof Closure) {
1714-
PHPUnit::withResponse($this)->assertTrue($value($this->session()->get($key)));
1714+
PHPUnit::withResponse($this)->assertFalse($value($this->session()->get($key)));
17151715
} else {
1716-
PHPUnit::withResponse($this)->assertEquals($value, $this->session()->get($key));
1716+
PHPUnit::withResponse($this)->assertNotEquals($value, $this->session()->get($key));
17171717
}
17181718

17191719
return $this;

tests/Testing/TestResponseTest.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,17 +2808,61 @@ public function testAssertSessionMissing(): void
28082808
$response->assertSessionMissing('foo');
28092809
}
28102810

2811-
#[TestWith(['foo', 'badvalue'])]
2812-
#[TestWith(['foo', null])]
2813-
#[TestWith([['foo', 'bar'], null])]
2814-
public function testAssertSessionMissingValue(array|string $key, mixed $value): void
2811+
#[TestWith(['foo', 'goodvalue'])]
2812+
#[TestWith([['foo', 'bar'], 'goodvalue'])]
2813+
public function testAssertSessionMissingValueIsPresent(array|string $key, mixed $value): void
2814+
{
2815+
$this->expectException(AssertionFailedError::class);
2816+
2817+
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));
2818+
2819+
$store->put('foo', 'goodvalue');
2820+
2821+
$response = TestResponse::fromBaseResponse(new Response());
2822+
$response->assertSessionMissing($key, $value);
2823+
}
2824+
2825+
public function testAssertSessionMissingValueIsPresentClosure(): void
28152826
{
28162827
$this->expectException(AssertionFailedError::class);
28172828

28182829
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));
28192830

28202831
$store->put('foo', 'goodvalue');
28212832

2833+
$key = 'foo';
2834+
2835+
$value = function ($value) {
2836+
return $value === 'goodvalue';
2837+
};
2838+
2839+
$response = TestResponse::fromBaseResponse(new Response());
2840+
$response->assertSessionMissing($key, $value);
2841+
}
2842+
2843+
#[TestWith(['foo', 'badvalue'])]
2844+
public function testAssertSessionMissingValueIsMissing(array|string $key, mixed $value): void
2845+
{
2846+
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));
2847+
2848+
$store->put('foo', 'goodvalue');
2849+
2850+
$response = TestResponse::fromBaseResponse(new Response());
2851+
$response->assertSessionMissing($key, $value);
2852+
}
2853+
2854+
public function testAssertSessionMissingValueIsMissingClosure(): void
2855+
{
2856+
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));
2857+
2858+
$store->put('foo', 'goodvalue');
2859+
2860+
$key = 'foo';
2861+
2862+
$value = function ($value) {
2863+
return $value === 'badvalue';
2864+
};
2865+
28222866
$response = TestResponse::fromBaseResponse(new Response());
28232867
$response->assertSessionMissing($key, $value);
28242868
}

0 commit comments

Comments
 (0)