diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index ff20fbeb65..869ade4ce8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -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); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php index c659f7e35e..ef36f3acd0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php @@ -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,