8000 bug #34411 [HttpKernel] Flatten "exception" controller argument if no… · symfony/symfony@1f73247 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f73247

Browse files
bug #34411 [HttpKernel] Flatten "exception" controller argument if not typed (chalasr)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] Flatten "exception" controller argument if not typed | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Fixes a BC break and makes it easier for libs to support both debug & error-handler e.g. api-platform/core#3246 (comment) Commits ------- 585216a [HttpKernel] Flatten "exception" controller argument if not typed
2 parents 278dcfb + 585216a commit 1f73247

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function onControllerArguments(ControllerArgumentsEvent $event)
9999
$r = new \ReflectionFunction(\Closure::fromCallable($event->getController()));
100100
$r = $r->getParameters()[$k] ?? null;
101101

102-
if ($r && $r->hasType() && FlattenException::class === $r->getType()->getName()) {
102+
if ($r && (!$r->hasType() || FlattenException::class === $r->getType()->getName())) {
103103
$arguments = $event->getArguments();
104104
$arguments[$k] = FlattenException::createFromThrowable($e);
105105
$event->setArguments($arguments);

src/Symfony/Component/HttpKernel/Tests/EventListener/ErrorListenerTest.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Log\LoggerInterface;
16-
use Symfony\Component\EventDispatcher\EventDispatcher;
1716
use Symfony\Component\ErrorHandler\Exception\FlattenException;
17+
use Symfony\Component\EventDispatcher\EventDispatcher;
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\Response;
2020
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
@@ -158,12 +158,11 @@ public function testCSPHeaderIsRemoved()
158158
$this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed');
159159
}
160160

161-
public function testOnControllerArguments()
161+
/**
162+
* @dataProvider controllerProvider
163+
*/
164+
public function testOnControllerArguments(callable $controller)
162165
{
163-
$controller = function (FlattenException $exception) {
164-
return new Response('OK: '.$exception->getMessage());
165-
};
166-
167166
$listener = new ErrorListener($controller, $this->createMock(LoggerInterface::class), true);
168167

169168
$kernel = $this->createMock(HttpKernelInterface::class);
@@ -181,6 +180,23 @@ public function testOnControllerArguments()
181180

182181
$this->assertSame('OK: foo', $event->getResponse()->getContent());
183182
}
183+
184+
public function controllerProvider()
185+
{
186+
yield [function (FlattenException $exception) {
187+
return new Response('OK: '.$exception->getMessage());
188+
}];
189+
190+
yield [function ($exception) {
191+
$this->assertInstanceOf(FlattenException::class, $exception);
192+
193+
return new Response('OK: '.$exception->getMessage());
194+
}];
195+
196+
yield [function (\Throwable $exception) {
197+
return new Response('OK: '.$exception->getMessage());
198+
}];
199+
}
184200
}
185201

186202
class TestLogger extends Logger implements DebugLoggerInterface

0 commit comments

Comments
 (0)
0