Skip to content

Commit 292614f

Browse files
authored
Merge pull request #575 from zigzagdev/feat/user-favorite-remove-application
feat: implement Application layer for removing favorites / お気に入り解除のApplication層実装
2 parents f2c9a2a + 7f1caa6 commit 292614f

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Packages\Features\CommandUseCases\UseCase\Favorite;
4+
5+
use App\Packages\Domains\Favorite\Interface\FavoriteRepositoryInterface;
6+
7+
final class RemoveFavoriteUseCase
8+
{
9+
public function __construct(
10+
private readonly FavoriteRepositoryInterface $favoriteRepository,
11+
) {}
12+
13+
public function handle(int $userId, int $worldHeritageSiteId): void
14+
{
15+
$this->favoriteRepository->removeFavorite($userId, $worldHeritageSiteId);
16+
}
17+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Packages\Features\Tests\CommandUseCases;
4+
5+
use App\Packages\Domains\Favorite\Interface\FavoriteRepositoryInterface;
6+
use App\Packages\Features\CommandUseCases\UseCase\Favorite\RemoveFavoriteUseCase;
7+
use Exception;
8+
use Mockery;
9+
use Mockery\MockInterface;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class RemoveFavoriteUseCaseTest extends TestCase
13+
{
14+
protected function tearDown(): void
15+
{
16+
Mockery::close();
17+
parent::tearDown();
18+
}
19+
20+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
21+
public function test_handle_calls_repository_removeFavorite_with_given_ids(): void
22+
{
23+
/** @var FavoriteRepositoryInterface|MockInterface $repository */
24+
$repository = Mockery::mock(FavoriteRepositoryInterface::class);
25+
$repository->shouldReceive('removeFavorite')
26+
->once()
27+
->with(1, 2);
28+
29+
(new RemoveFavoriteUseCase($repository))->handle(1, 2);
30+
}
31+
32+
public function test_handle_propagates_exception_when_user_not_found(): void
33+
{
34+
/** @var FavoriteRepositoryInterface|MockInterface $repository */
35+
$repository = Mockery::mock(FavoriteRepositoryInterface::class);
36+
$repository->shouldReceive('removeFavorite')
37+
->once()
38+
->with(999999, 2)
39+
->andThrow(new Exception('User not found.'));
40+
41+
$this->expectException(Exception::class);
42+
$this->expectExceptionMessage('User not found.');
43+
44+
(new RemoveFavoriteUseCase($repository))->handle(999999, 2);
45+
}
46+
}

0 commit comments

Comments
 (0)