File tree Expand file tree Collapse file tree
src/app/Packages/Features
CommandUseCases/UseCase/Favorite Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments