[FrameworkBundle] fix AbstractController::handleForm()

This commit is contained in:
Nicolas Grekas 2021-05-12 09:43:11 +02:00
parent b14d76921f
commit 777c3c25b2
2 changed files with 3 additions and 3 deletions

View File

@ -314,7 +314,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
} else {
$response = $render($form, $data, $request);
if ($submitted && 200 === $response->getStatusCode()) {
if ($response instanceof Response && $submitted && 200 === $response->getStatusCode()) {
$response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
}
}

View File

@ -494,12 +494,12 @@ class AbstractControllerTest extends TestCase
{
$form = $this->createMock(FormInterface::class);
$form->expects($this->once())->method('isSubmitted')->willReturn(true);
$form->expects($this->once())->method('isValid')->willReturn(true);
$form->expects($this->once())->method('isValid')->willReturn(false);
$controller = $this->createController();
$this->expectException(\TypeError::class);
$this->expectExceptionMessage('The "$onSuccess" callable passed to "Symfony\Bundle\FrameworkBundle\Tests\Controller\TestAbstractController::handleForm()" must return a Response, "string" returned.');
$this->expectExceptionMessage('The "$render" callable passed to "Symfony\Bundle\FrameworkBundle\Tests\Controller\TestAbstractController::handleForm()" must return a Response, "string" returned.');
$response = $controller->handleForm(
$form,