From 636f338e4ecc14b3c9fe660e2f606abc442813bf Mon Sep 17 00:00:00 2001 From: William Adjei Date: Wed, 13 Dec 2023 22:30:30 +0000 Subject: [PATCH 1/7] Validation tests for custom ModelManagerException message support --- ...ModelManagerExceptionMessageController.php | 18 + ...ModelManagerThrowableMessageController.php | 18 + tests/Controller/CRUDControllerTest.php | 487 ++++++++++++++++++ 3 files changed, 523 insertions(+) create mode 100644 tests/App/Controller/CustomModelManagerExceptionMessageController.php create mode 100644 tests/App/Controller/CustomModelManagerThrowableMessageController.php diff --git a/tests/App/Controller/CustomModelManagerExceptionMessageController.php b/tests/App/Controller/CustomModelManagerExceptionMessageController.php new file mode 100644 index 0000000000..4d4c15a3cf --- /dev/null +++ b/tests/App/Controller/CustomModelManagerExceptionMessageController.php @@ -0,0 +1,18 @@ +controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); } + public function testBatchActionDeleteWithModelManagerExceptionAndCustomError(): void + { + $modelManager = $this->createMock(ModelManagerInterface::class); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $modelManager->expects(static::once()) + ->method('batchDelete') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $this->admin->expects(static::once()) + ->method('getModelManager') + ->willReturn($modelManager); + + $this->admin->expects(static::once()) + ->method('getFilterParameters') + ->willReturn(['foo' => 'bar']); + + $customController = new CustomModelManagerExceptionMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $result = $customController->batchActionDelete($this->createMock(ProxyQueryInterface::class)); + + static::assertInstanceOf(RedirectResponse::class, $result); + static::assertSame( + [CustomModelManagerExceptionMessageController::ERROR_MESSAGE], + $this->session->getFlashBag()->get('sonata_flash_error') + ); + static::assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl()); + } + + public function testBatchActionDeleteWithModelManagerThrowableCustomErrorAndHandleThrowableOnly(): void + { + $modelManager = $this->createMock(ModelManagerInterface::class); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $modelManager->expects(static::once()) + ->method('batchDelete') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $this->admin->expects(static::once()) + ->method('getModelManager') + ->willReturn($modelManager); + + $this->admin->expects(static::once()) + ->method('getFilterParameters') + ->willReturn(['foo' => 'bar']); + + $customController = new CustomModelManagerThrowableMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $this->translator->expects(static::never())->method('trans'); + + $result = $customController->batchActionDelete($this->createMock(ProxyQueryInterface::class)); + + static::assertInstanceOf(RedirectResponse::class, $result); + static::assertSame( + [CustomModelManagerThrowableMessageController::ERROR_MESSAGE], + $this->session->getFlashBag()->get('sonata_flash_error') + ); + static::assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl()); + } + public function testShowActionNotFoundException(): void { $this->request->attributes->set($this->admin->getIdParameter(), 21); @@ -1350,6 +1431,80 @@ public function testDeleteActionError(string $expectedToStringValue, string $toS static::assertSame('list', $response->getTargetUrl()); } + public function testDeleteActionWithModelManagerExceptionCustomError(): void + { + $this->request->attributes->set($this->admin->getIdParameter(), 21); + + $object = new \stdClass(); + + $this->admin->expects(static::once())->method('getObject')->willReturn($object); + $this->admin->expects(static::once())->method('checkAccess')->with(static::equalTo('delete')); + + $this->translator->expects(static::never())->method('trans'); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('delete') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $this->request->setMethod(Request::METHOD_DELETE); + $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); + + $customController = new CustomModelManagerExceptionMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $response = $customController->deleteAction($this->request); + + static::assertInstanceOf(RedirectResponse::class, $response); + static::assertSame([CustomModelManagerExceptionMessageController::ERROR_MESSAGE], $this->session->getFlashBag()->get('sonata_flash_error')); + static::assertSame('list', $response->getTargetUrl()); + } + + public function testDeleteActionWithModelManagerThrowableCustomError(): void + { + $this->request->attributes->set($this->admin->getIdParameter(), 21); + + $object = new \stdClass(); + + $this->admin->expects(static::once())->method('getObject')->willReturn($object); + $this->admin->expects(static::once())->method('checkAccess')->with(static::equalTo('delete')); + + $this->translator->expects(static::never())->method('trans'); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('delete') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $this->request->setMethod(Request::METHOD_DELETE); + $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); + + $customController = new CustomModelManagerThrowableMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $response = $customController->deleteAction($this->request); + + static::assertInstanceOf(RedirectResponse::class, $response); + static::assertSame([CustomModelManagerThrowableMessageController::ERROR_MESSAGE], $this->session->getFlashBag()->get('sonata_flash_error')); + static::assertSame('list', $response->getTargetUrl()); + } + public function testDeleteActionInvalidCsrfToken(): void { $this->request->attributes->set($this->admin->getIdParameter(), 21); @@ -1652,6 +1807,176 @@ public function testEditActionError(string $expectedToStringValue, string $toStr static::assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all()); } + public function testEditActionWithModelManagerExceptionAndCustomError(): void + { + $this->request->attributes->set($this->admin->getIdParameter(), 21); + + $object = new \stdClass(); + + $this->admin->expects(static::once()) + ->method('getObject') + ->willReturn($object); + + $this->admin->expects(static::once()) + ->method('checkAccess') + ->with(static::equalTo('edit')); + + $this->admin + ->method('getNormalizedIdentifier') + ->with(static::equalTo($object)) + ->willReturn('foo_normalized'); + + $form = $this->createMock(Form::class); + + $this->admin->expects(static::once()) + ->method('getForm') + ->willReturn($form); + + $form->expects(static::once()) + ->method('isSubmitted') + ->willReturn(true); + + $form->expects(static::once()) + ->method('isValid') + ->willReturn(true); + + $this->translator->expects(static::never())->method('trans'); + + $this->request->setMethod(Request::METHOD_POST); + + $formView = $this->createMock(FormView::class); + + $form + ->method('createView') + ->willReturn($formView); + + $form->expects(static::once()) + ->method('getData') + ->willReturn($object); + + $this->twig + ->expects(static::once()) + ->method('render') + ->with('@SonataAdmin/CRUD/edit.html.twig', [ + 'admin' => $this->admin, + 'base_template' => '@SonataAdmin/standard_layout.html.twig', + 'action' => 'edit', + 'form' => $formView, + 'object' => $object, + 'objectId' => 'foo_normalized', + ]); + + $customController = new CustomModelManagerExceptionMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('update') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $response = $customController->editAction($this->request); + + static::assertInstanceOf(Response::class, $response); + + static::assertSame( + ['sonata_flash_error' => [CustomModelManagerExceptionMessageController::ERROR_MESSAGE]], + $this->session->getFlashBag()->all() + ); + } + + public function testEditActionWithModelManagerThrowableAndCustomError(): void + { + $this->request->attributes->set($this->admin->getIdParameter(), 21); + + $object = new \stdClass(); + + $this->admin->expects(static::once()) + ->method('getObject') + ->willReturn($object); + + $this->admin->expects(static::once()) + ->method('checkAccess') + ->with(static::equalTo('edit')); + + $this->admin + ->method('getNormalizedIdentifier') + ->with(static::equalTo($object)) + ->willReturn('foo_normalized'); + + $form = $this->createMock(Form::class); + + $this->admin->expects(static::once()) + ->method('getForm') + ->willReturn($form); + + $form->expects(static::once()) + ->method('isSubmitted') + ->willReturn(true); + + $form->expects(static::once()) + ->method('isValid') + ->willReturn(true); + + $this->translator->expects(static::never())->method('trans'); + + $this->request->setMethod(Request::METHOD_POST); + + $formView = $this->createMock(FormView::class); + + $form + ->method('createView') + ->willReturn($formView); + + $form->expects(static::once()) + ->method('getData') + ->willReturn($object); + + $this->twig + ->expects(static::once()) + ->method('render') + ->with('@SonataAdmin/CRUD/edit.html.twig', [ + 'admin' => $this->admin, + 'base_template' => '@SonataAdmin/standard_layout.html.twig', + 'action' => 'edit', + 'form' => $formView, + 'object' => $object, + 'objectId' => 'foo_normalized', + ]); + + $customController = new CustomModelManagerThrowableMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('update') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $response = $customController->editAction($this->request); + + static::assertInstanceOf(Response::class, $response); + + static::assertSame( + ['sonata_flash_error' => [CustomModelManagerThrowableMessageController::ERROR_MESSAGE]], + $this->session->getFlashBag()->all() + ); + } + public function testEditActionAjaxSuccess(): void { $this->request->attributes->set($this->admin->getIdParameter(), 21); @@ -2324,6 +2649,168 @@ public function testCreateActionWithModelManagerException(string $expectedToStri static::assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all()); } + public function testCreateActionWithModelManagerExceptionAndCustomError(): void + { + $this->admin->expects(static::once()) + ->method('checkAccess') + ->with(static::equalTo('create')); + + $this->admin + ->method('getClass') + ->willReturn(\stdClass::class); + + $object = new \stdClass(); + + $this->admin->expects(static::once()) + ->method('getNewInstance') + ->willReturn($object); + + $form = $this->createMock(Form::class); + + $this->admin->expects(static::once()) + ->method('getForm') + ->willReturn($form); + + $form->expects(static::once()) + ->method('isValid') + ->willReturn(true); + + $this->translator->expects(static::never())->method('trans'); + + $form->expects(static::once()) + ->method('isSubmitted') + ->willReturn(true); + + $form->expects(static::once()) + ->method('getData') + ->willReturn($object); + + $this->request->setMethod(Request::METHOD_POST); + + $formView = $this->createMock(FormView::class); + + $form + ->method('createView') + ->willReturn($formView); + + $this->twig + ->expects(static::once()) + ->method('render') + ->with('@SonataAdmin/CRUD/edit.html.twig', [ + 'admin' => $this->admin, + 'base_template' => '@SonataAdmin/standard_layout.html.twig', + 'action' => 'create', + 'form' => $formView, + 'object' => $object, + 'objectId' => null, + ]); + + $customController = new CustomModelManagerExceptionMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('create') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $response = $customController->createAction($this->request); + + static::assertInstanceOf(Response::class, $response); + static::assertSame( + ['sonata_flash_error' => [CustomModelManagerExceptionMessageController::ERROR_MESSAGE]], + $this->session->getFlashBag()->all() + ); + } + + public function testCreateActionWithModelManagerThrowableAndCustomError(): void + { + $this->admin->expects(static::once()) + ->method('checkAccess') + ->with(static::equalTo('create')); + + $this->admin + ->method('getClass') + ->willReturn(\stdClass::class); + + $object = new \stdClass(); + + $this->admin->expects(static::once()) + ->method('getNewInstance') + ->willReturn($object); + + $form = $this->createMock(Form::class); + + $this->admin->expects(static::once()) + ->method('getForm') + ->willReturn($form); + + $form->expects(static::once()) + ->method('isValid') + ->willReturn(true); + + $this->translator->expects(static::never())->method('trans'); + + $form->expects(static::once()) + ->method('isSubmitted') + ->willReturn(true); + + $form->expects(static::once()) + ->method('getData') + ->willReturn($object); + + $this->request->setMethod(Request::METHOD_POST); + + $formView = $this->createMock(FormView::class); + + $form + ->method('createView') + ->willReturn($formView); + + $this->twig + ->expects(static::once()) + ->method('render') + ->with('@SonataAdmin/CRUD/edit.html.twig', [ + 'admin' => $this->admin, + 'base_template' => '@SonataAdmin/standard_layout.html.twig', + 'action' => 'create', + 'form' => $formView, + 'object' => $object, + 'objectId' => null, + ]); + + $customController = new CustomModelManagerThrowableMessageController(); + $customController->setContainer($this->container); + $customController->configureAdmin($this->request); + + $exception = new ModelManagerException( + $message = 'message', + 1234, + new \Exception($previousExceptionMessage = 'very useful message') + ); + + $this->admin->expects(static::once()) + ->method('create') + ->willReturnCallback(static function () use ($exception): void { + throw $exception; + }); + + $response = $customController->createAction($this->request); + + static::assertInstanceOf(Response::class, $response); + static::assertSame( + ['sonata_flash_error' => [CustomModelManagerThrowableMessageController::ERROR_MESSAGE]], + $this->session->getFlashBag()->all() + ); + } + public function testCreateActionAjaxSuccess(): void { $object = new \stdClass(); From 61b8409b8f2144eb2c2094e10461f42dac5d14e8 Mon Sep 17 00:00:00 2001 From: William Adjei Date: Wed, 13 Dec 2023 23:06:27 +0000 Subject: [PATCH 2/7] Add support for customising ModelManagerException messages (#8137) --- src/Controller/CRUDController.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index b7245b8d91..6dc550ae1a 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -170,11 +170,10 @@ public function batchActionDelete(ProxyQueryInterface $query): Response ); } catch (ModelManagerException $e) { // NEXT_MAJOR: Remove this catch. - $this->handleModelManagerException($e); - + $errorMessage = $this->handleModelManagerException($e); $this->addFlash( 'sonata_flash_error', - $this->trans('flash_batch_delete_error', [], 'SonataAdminBundle') + $errorMessage ?? $this->trans('flash_batch_delete_error', [], 'SonataAdminBundle') ); } catch (ModelManagerThrowable $e) { $errorMessage = $this->handleModelManagerThrowable($e); @@ -229,7 +228,7 @@ public function deleteAction(Request $request): Response ); } catch (ModelManagerException $e) { // NEXT_MAJOR: Remove this catch. - $this->handleModelManagerException($e); + $errorMessage = $this->handleModelManagerException($e); if ($this->isXmlHttpRequest($request)) { return $this->renderJson(['result' => 'error']); @@ -237,7 +236,7 @@ public function deleteAction(Request $request): Response $this->addFlash( 'sonata_flash_error', - $this->trans( + $errorMessage ?? $this->trans( 'flash_delete_error', ['%name%' => $this->escapeHtml($objectName)], 'SonataAdminBundle' @@ -295,7 +294,6 @@ public function editAction(Request $request): Response if (null !== $preResponse) { return $preResponse; } - $this->admin->setSubject($existingObject); $objectId = $this->admin->getNormalizedIdentifier($existingObject); \assert(null !== $objectId); @@ -334,7 +332,7 @@ public function editAction(Request $request): Response return $this->redirectTo($request, $existingObject); } catch (ModelManagerException $e) { // NEXT_MAJOR: Remove this catch. - $this->handleModelManagerException($e); + $errorMessage = $this->handleModelManagerException($e); $isFormValid = false; } catch (ModelManagerThrowable $e) { @@ -610,7 +608,7 @@ public function createAction(Request $request): Response return $this->redirectTo($request, $newObject); } catch (ModelManagerException $e) { // NEXT_MAJOR: Remove this catch. - $this->handleModelManagerException($e); + $errorMessage = $this->handleModelManagerException($e); $isFormValid = false; } catch (ModelManagerThrowable $e) { @@ -1108,12 +1106,10 @@ protected function getBaseTemplate(): string /** * @throws \Exception */ - protected function handleModelManagerException(\Exception $exception): void + protected function handleModelManagerException(\Exception $exception) { if ($exception instanceof ModelManagerThrowable) { - $this->handleModelManagerThrowable($exception); - - return; + return $this->handleModelManagerThrowable($exception); } @trigger_error(sprintf( From 02e9b95a5d709c0e1bab07f412fdfb9a9ace1bca Mon Sep 17 00:00:00 2001 From: William Adjei Date: Thu, 14 Dec 2023 22:47:37 +0000 Subject: [PATCH 3/7] psalm and phpstan --- phpunit.xml.dist | 1 + src/Controller/CRUDController.php | 1 + src/DependencyInjection/Configuration.php | 1 + .../CustomModelManagerExceptionMessageController.php | 5 ++++- .../CustomModelManagerThrowableMessageController.php | 5 ++++- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9e502aae56..18ab0562c4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -36,5 +36,6 @@ It's auto-generated by sonata-project/dev-kit package. + diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 6dc550ae1a..7d0a02b7d3 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1105,6 +1105,7 @@ protected function getBaseTemplate(): string /** * @throws \Exception + * @return string|null|void A custom error message to display in the flag bag instead of the generic one */ protected function handleModelManagerException(\Exception $exception) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8c6b9d64b0..724831f097 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -174,6 +174,7 @@ final class Configuration implements ConfigurationInterface { /** * @psalm-suppress UndefinedInterfaceMethod + * @psalm-suppress PossiblyNullReference - end() can return null, apparently * * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 */ diff --git a/tests/App/Controller/CustomModelManagerExceptionMessageController.php b/tests/App/Controller/CustomModelManagerExceptionMessageController.php index 4d4c15a3cf..09ef647af1 100644 --- a/tests/App/Controller/CustomModelManagerExceptionMessageController.php +++ b/tests/App/Controller/CustomModelManagerExceptionMessageController.php @@ -7,11 +7,14 @@ use Exception; use Sonata\AdminBundle\Controller\CRUDController; +/** + * @phpstan-extends CRUDController + */ final class CustomModelManagerExceptionMessageController extends CRUDController { public const ERROR_MESSAGE = 'message from model manager exception'; - protected function handleModelManagerException(Exception $exception) + protected function handleModelManagerException(Exception $exception): string { return self::ERROR_MESSAGE; } diff --git a/tests/App/Controller/CustomModelManagerThrowableMessageController.php b/tests/App/Controller/CustomModelManagerThrowableMessageController.php index 4395807410..83066178f5 100644 --- a/tests/App/Controller/CustomModelManagerThrowableMessageController.php +++ b/tests/App/Controller/CustomModelManagerThrowableMessageController.php @@ -7,11 +7,14 @@ use Sonata\AdminBundle\Controller\CRUDController; use Sonata\AdminBundle\Exception\ModelManagerThrowable; +/** + * @phpstan-extends CRUDController + */ final class CustomModelManagerThrowableMessageController extends CRUDController { public const ERROR_MESSAGE = 'message from model manager throwable'; - protected function handleModelManagerThrowable(ModelManagerThrowable $exception) + protected function handleModelManagerThrowable(ModelManagerThrowable $exception): string { return self::ERROR_MESSAGE; } From d85a41e61ef46d000e983cf5bc47c62c3d4b93b2 Mon Sep 17 00:00:00 2001 From: William Adjei Date: Fri, 15 Dec 2023 09:14:32 +0000 Subject: [PATCH 4/7] restore dist config --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 18ab0562c4..9e502aae56 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -36,6 +36,5 @@ It's auto-generated by sonata-project/dev-kit package. - From ed376c04e8c8a868316749bce6a15496333d54e9 Mon Sep 17 00:00:00 2001 From: William Adjei Date: Fri, 15 Dec 2023 09:20:40 +0000 Subject: [PATCH 5/7] cs-fix-php --- src/Controller/CRUDController.php | 3 ++- .../CustomModelManagerExceptionMessageController.php | 12 ++++++++++-- .../CustomModelManagerThrowableMessageController.php | 9 +++++++++ tests/Controller/CRUDControllerTest.php | 1 - 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 7d0a02b7d3..b31b2ae551 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1105,7 +1105,8 @@ protected function getBaseTemplate(): string /** * @throws \Exception - * @return string|null|void A custom error message to display in the flag bag instead of the generic one + * + * @return string|void|null A custom error message to display in the flag bag instead of the generic one */ protected function handleModelManagerException(\Exception $exception) { diff --git a/tests/App/Controller/CustomModelManagerExceptionMessageController.php b/tests/App/Controller/CustomModelManagerExceptionMessageController.php index 09ef647af1..2aba1eb8d2 100644 --- a/tests/App/Controller/CustomModelManagerExceptionMessageController.php +++ b/tests/App/Controller/CustomModelManagerExceptionMessageController.php @@ -2,9 +2,17 @@ declare(strict_types=1); +/* + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Sonata\AdminBundle\Tests\App\Controller; -use Exception; use Sonata\AdminBundle\Controller\CRUDController; /** @@ -14,7 +22,7 @@ final class CustomModelManagerExceptionMessageController extends CRUDController { public const ERROR_MESSAGE = 'message from model manager exception'; - protected function handleModelManagerException(Exception $exception): string + protected function handleModelManagerException(\Exception $exception): string { return self::ERROR_MESSAGE; } diff --git a/tests/App/Controller/CustomModelManagerThrowableMessageController.php b/tests/App/Controller/CustomModelManagerThrowableMessageController.php index 83066178f5..080b267e5f 100644 --- a/tests/App/Controller/CustomModelManagerThrowableMessageController.php +++ b/tests/App/Controller/CustomModelManagerThrowableMessageController.php @@ -2,6 +2,15 @@ declare(strict_types=1); +/* + * This file is part of the Sonata Project package. + * + * (c) Thomas Rabaix + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Sonata\AdminBundle\Tests\App\Controller; use Sonata\AdminBundle\Controller\CRUDController; diff --git a/tests/Controller/CRUDControllerTest.php b/tests/Controller/CRUDControllerTest.php index e851839ef0..7b4b55fcea 100644 --- a/tests/Controller/CRUDControllerTest.php +++ b/tests/Controller/CRUDControllerTest.php @@ -34,7 +34,6 @@ use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; use Sonata\AdminBundle\Tests\App\Controller\CustomModelManagerExceptionMessageController; use Sonata\AdminBundle\Tests\App\Controller\CustomModelManagerThrowableMessageController; -use Sonata\AdminBundle\Tests\App\Exception\NonModelManagerException; use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController; use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchOtherController; use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController; From 228325809e9188973299b9baffc64cdc677abee6 Mon Sep 17 00:00:00 2001 From: William Adjei Date: Fri, 15 Dec 2023 09:26:00 +0000 Subject: [PATCH 6/7] remove void from handleModelManagerException signature --- src/Controller/CRUDController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index b31b2ae551..902a700f57 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1106,7 +1106,7 @@ protected function getBaseTemplate(): string /** * @throws \Exception * - * @return string|void|null A custom error message to display in the flag bag instead of the generic one + * @return string|null A custom error message to display in the flag bag instead of the generic one */ protected function handleModelManagerException(\Exception $exception) { @@ -1130,6 +1130,8 @@ protected function handleModelManagerException(\Exception $exception) $context['previous_exception_message'] = $exception->getPrevious()->getMessage(); } $this->getLogger()->error($exception->getMessage(), $context); + + return null; } /** From dadfd446ce000f922fae6d09326432f2e515f38e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 15 Dec 2023 11:09:11 +0100 Subject: [PATCH 7/7] Remove unused psalm-suppress --- src/DependencyInjection/Configuration.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 724831f097..8c6b9d64b0 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -174,7 +174,6 @@ final class Configuration implements ConfigurationInterface { /** * @psalm-suppress UndefinedInterfaceMethod - * @psalm-suppress PossiblyNullReference - end() can return null, apparently * * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 */