Skip to content

Commit 565b6e5

Browse files
committed
Merge remote-tracking branch 'upstream/9.x' into 9.x
2 parents 02d1009 + 1a2e484 commit 565b6e5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,13 @@ public function assertSessionMissing($key)
14391439
*/
14401440
protected function session()
14411441
{
1442-
return app('session.store');
1442+
$session = app('session.store');
1443+
1444+
if (! $session->isStarted()) {
1445+
$session->start();
1446+
}
1447+
1448+
return $session;
14431449
}
14441450

14451451
/**

tests/Testing/TestResponseTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,25 @@ public function testAssertSessionHasErrors()
18401840
$response->assertSessionHasErrors(['foo']);
18411841
}
18421842

1843+
public function testAssertJsonSerializedSessionHasErrors()
1844+
{
1845+
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1), null, 'json'));
1846+
1847+
$store->put('errors', $errorBag = new ViewErrorBag);
1848+
1849+
$errorBag->put('default', new MessageBag([
1850+
'foo' => [
1851+
'foo is required',
1852+
],
1853+
]));
1854+
1855+
$store->save(); // Required to serialize error bag to JSON
1856+
1857+
$response = TestResponse::fromBaseResponse(new Response());
1858+
1859+
$response->assertSessionHasErrors(['foo']);
1860+
}
1861+
18431862
public function testAssertSessionDoesntHaveErrors()
18441863
{
18451864
$this->expectException(AssertionFailedError::class);

0 commit comments

Comments
 (0)