Skip to content

Commit 9590a9b

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [LokaliseBridge] Fix push command --delete-missing options when there are no missing messages fix bad help message in cache warmup command [Console] Fix OutputFormatterStyleStack::getCurrent return type Count cookie parts before accessing the second Fix RequestStack state if throwable is thrown [Serializer] Fix caching context-aware encoders/decoders in ChainEncoder/ChainDecoder
2 parents 20638a0 + 31fa9ec commit 9590a9b

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

HttpKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
7070
{
7171
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
7272

73+
$this->requestStack->push($request);
7374
try {
7475
return $this->handleRaw($request, $type);
7576
} catch (\Exception $e) {
@@ -83,6 +84,8 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
8384
}
8485

8586
return $this->handleThrowable($e, $request, $type);
87+
} finally {
88+
$this->requestStack->pop();
8689
}
8790
}
8891

@@ -121,8 +124,6 @@ public function terminateWithException(\Throwable $exception, Request $request =
121124
*/
122125
private function handleRaw(Request $request, int $type = self::MAIN_REQUEST): Response
123126
{
124-
$this->requestStack->push($request);
125-
126127
// request
127128
$event = new RequestEvent($this, $request, $type);
128129
$this->dispatcher->dispatch($event, KernelEvents::REQUEST);
@@ -199,7 +200,6 @@ private function filterResponse(Response $response, Request $request, int $type)
199200
private function finishRequest(Request $request, int $type)
200201
{
201202
$this->dispatcher->dispatch(new FinishRequestEvent($this, $request, $type), KernelEvents::FINISH_REQUEST);
202-
$this->requestStack->pop();
203203
}
204204

205205
/**

Tests/HttpKernelTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,45 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
4040
$kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
4141
}
4242

43+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsTrue()
44+
{
45+
$requestStack = new RequestStack();
46+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
47+
48+
try {
49+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
50+
} catch (\Throwable $exception) {
51+
}
52+
53+
self::assertNull($requestStack->getCurrentRequest());
54+
}
55+
56+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsFalse()
57+
{
58+
$requestStack = new RequestStack();
59+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack);
60+
61+
try {
62+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
63+
} catch (\Throwable $exception) {
64+
}
65+
66+
self::assertNull($requestStack->getCurrentRequest());
67+
}
68+
69+
public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable()
70+
{
71+
$requestStack = new RequestStack();
72+
$kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \Error(); }, $requestStack);
73+
74+
try {
75+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
76+
} catch (\Throwable $exception) {
77+
}
78+
79+
self::assertNull($requestStack->getCurrentRequest());
80+
}
81+
4382
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered()
4483
{
4584
$this->expectException(\RuntimeException::class);

0 commit comments

Comments
 (0)