From c1a2a7a5c9d355b286ee2282fc1459bd6df94688 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 22 Apr 2024 09:23:30 +0200 Subject: [PATCH] Fix tests --- src/EventSubscriber/ApiExceptionSubscriber.php | 3 ++- tests/Unit/Service/Security/SecurityServiceTest.php | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/EventSubscriber/ApiExceptionSubscriber.php b/src/EventSubscriber/ApiExceptionSubscriber.php index 599960222..8792124dc 100644 --- a/src/EventSubscriber/ApiExceptionSubscriber.php +++ b/src/EventSubscriber/ApiExceptionSubscriber.php @@ -21,6 +21,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Throwable; /** * @internal @@ -42,7 +43,7 @@ public function onKernelException(ExceptionEvent $event): void if(!$exception instanceof ApiExceptionInterface && !$this->isStudioApiCall($request->getPathInfo())) { return; } - + /** @var ApiExceptionInterface $exception */ $response = new JsonResponse( [ 'message' => $exception->getMessage(), diff --git a/tests/Unit/Service/Security/SecurityServiceTest.php b/tests/Unit/Service/Security/SecurityServiceTest.php index e0ed4c647..e83dc2e79 100644 --- a/tests/Unit/Service/Security/SecurityServiceTest.php +++ b/tests/Unit/Service/Security/SecurityServiceTest.php @@ -19,6 +19,7 @@ use Codeception\Test\Unit; use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\Tool\TmpStoreResolverInterface; +use Pimcore\Bundle\StudioApiBundle\Exception\AccessDeniedException; use Pimcore\Bundle\StudioApiBundle\Request\Credentials; use Pimcore\Bundle\StudioApiBundle\Service\SecurityService; use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface; @@ -49,7 +50,8 @@ public function testInvalidPassword(): void { $securityService = $this->mockSecurityService(false); - $this->expectExceptionMessage('Invalid credentials'); + $this->expectException(AccessDeniedException::class); + $this->expectExceptionMessage('Bad credentials'); $securityService->authenticateUser(new Credentials('test', 'test')); } @@ -60,7 +62,8 @@ public function testUserNotFound(): void { $securityService = $this->mockSecurityService(false, false); - $this->expectExceptionMessage('Invalid credentials'); + $this->expectException(AccessDeniedException::class); + $this->expectExceptionMessage('Bad credentials'); $securityService->authenticateUser(new Credentials('test', 'test')); }