From a2e8edadc773fb7472883dcde8c8bc5516f4d258 Mon Sep 17 00:00:00 2001 From: bidi Date: Wed, 11 Sep 2024 23:09:08 +0300 Subject: [PATCH] phpcs, phpunit fixes Signed-off-by: bidi --- .../src/Repository/UserAvatarRepository.php | 2 +- src/User/src/Service/UserService.php | 2 +- src/User/src/Service/UserServiceInterface.php | 2 ++ test/Unit/User/Service/UserServiceTest.php | 30 +++++++++++-------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/User/src/Repository/UserAvatarRepository.php b/src/User/src/Repository/UserAvatarRepository.php index 8b8efd8e..8ba8a90e 100644 --- a/src/User/src/Repository/UserAvatarRepository.php +++ b/src/User/src/Repository/UserAvatarRepository.php @@ -18,7 +18,7 @@ class UserAvatarRepository extends EntityRepository public function deleteAvatar(string $uuid): mixed { $uuid = Uuid::fromString($uuid)->getBytes(); - $qb = $this->getEntityManager()->createQueryBuilder(); + $qb = $this->getEntityManager()->createQueryBuilder(); $qb->delete(UserAvatar::class, 'user_avatar') ->where('user_avatar.uuid = :uuid') ->setParameter('uuid', $uuid); diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index b1f8d52e..02de9ea2 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -222,7 +222,7 @@ protected function createAvatar(User $user, UploadedFile $uploadedFile): UserAva public function deleteAvatar(User $user): void { - $path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString()); + $path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString()); $avatar = $user->getAvatar(); $this->deleteAvatarFile($path . $avatar->getName()); $this->userAvatarRepository->deleteAvatar($user->getAvatar()->getUuid()->toString()); diff --git a/src/User/src/Service/UserServiceInterface.php b/src/User/src/Service/UserServiceInterface.php index fe98d861..ae181dea 100644 --- a/src/User/src/Service/UserServiceInterface.php +++ b/src/User/src/Service/UserServiceInterface.php @@ -34,6 +34,8 @@ public function deleteExpiredRememberMeTokens(): void; public function updateUser(User $user, array $data = []): UserInterface; + public function deleteAvatar(User $user): void; + public function deleteAvatarFile(string $path): bool; public function exists(string $email = '', ?string $uuid = ''): bool; diff --git a/test/Unit/User/Service/UserServiceTest.php b/test/Unit/User/Service/UserServiceTest.php index a7c403bc..897ad076 100644 --- a/test/Unit/User/Service/UserServiceTest.php +++ b/test/Unit/User/Service/UserServiceTest.php @@ -9,6 +9,7 @@ use Frontend\App\Common\Message; use Frontend\App\Service\CookieServiceInterface; use Frontend\User\Entity\User; +use Frontend\User\Repository\UserAvatarRepository; use Frontend\User\Repository\UserRepository; use Frontend\User\Repository\UserRoleRepository; use Frontend\User\Service\UserRoleServiceInterface; @@ -30,6 +31,7 @@ public function testWillInstantiate(): void $this->createMock(UserRoleServiceInterface::class), $this->createMock(TemplateRendererInterface::class), $this->createMock(UserRepository::class), + $this->createMock(UserAvatarRepository::class), $this->createMock(UserRoleRepository::class), [] ); @@ -42,12 +44,13 @@ public function testWillInstantiate(): void */ public function testCreateUserThrowsDuplicateException(): void { - $cookieService = $this->createMock(CookieServiceInterface::class); - $mailService = $this->createMock(MailService::class); - $userRoleService = $this->createMock(UserRoleServiceInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $userRepository = $this->createMock(UserRepository::class); - $userRoleRepository = $this->createMock(UserRoleRepository::class); + $cookieService = $this->createMock(CookieServiceInterface::class); + $mailService = $this->createMock(MailService::class); + $userRoleService = $this->createMock(UserRoleServiceInterface::class); + $template = $this->createMock(TemplateRendererInterface::class); + $userRepository = $this->createMock(UserRepository::class); + $userAvatarRepository = $this->createMock(UserAvatarRepository::class); + $userRoleRepository = $this->createMock(UserRoleRepository::class); $userRepository->expects($this->once())->method('exists')->willReturn(new User()); $this->expectException(Exception::class); @@ -59,6 +62,7 @@ public function testCreateUserThrowsDuplicateException(): void $userRoleService, $template, $userRepository, + $userAvatarRepository, $userRoleRepository, [] ); @@ -71,12 +75,13 @@ public function testCreateUserThrowsDuplicateException(): void */ public function testCreateUserThrowsRestrictionRolesException(): void { - $cookieService = $this->createMock(CookieServiceInterface::class); - $mailService = $this->createMock(MailService::class); - $userRoleService = $this->createMock(UserRoleServiceInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $userRepository = $this->createMock(UserRepository::class); - $userRoleRepository = $this->createMock(UserRoleRepository::class); + $cookieService = $this->createMock(CookieServiceInterface::class); + $mailService = $this->createMock(MailService::class); + $userRoleService = $this->createMock(UserRoleServiceInterface::class); + $template = $this->createMock(TemplateRendererInterface::class); + $userRepository = $this->createMock(UserRepository::class); + $userAvatarRepository = $this->createMock(UserAvatarRepository::class); + $userRoleRepository = $this->createMock(UserRoleRepository::class); $userRepository->expects($this->once())->method('exists')->willReturn(null); $this->expectException(Exception::class); @@ -88,6 +93,7 @@ public function testCreateUserThrowsRestrictionRolesException(): void $userRoleService, $template, $userRepository, + $userAvatarRepository, $userRoleRepository, [] );