Skip to content

Commit

Permalink
phpcs, phpunit fixes
Browse files Browse the repository at this point in the history
Signed-off-by: bidi <[email protected]>
  • Loading branch information
bidi47 committed Sep 11, 2024
1 parent 2db2fff commit a2e8eda
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/User/src/Repository/UserAvatarRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/User/src/Service/UserServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 18 additions & 12 deletions test/Unit/User/Service/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
[]
);
Expand All @@ -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);
Expand All @@ -59,6 +62,7 @@ public function testCreateUserThrowsDuplicateException(): void
$userRoleService,
$template,
$userRepository,
$userAvatarRepository,
$userRoleRepository,
[]
);
Expand All @@ -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);
Expand All @@ -88,6 +93,7 @@ public function testCreateUserThrowsRestrictionRolesException(): void
$userRoleService,
$template,
$userRepository,
$userAvatarRepository,
$userRoleRepository,
[]
);
Expand Down

0 comments on commit a2e8eda

Please sign in to comment.