Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Packages\Features\CommandUseCases\UseCase\Favorite;

use App\Packages\Domains\Favorite\Interface\FavoriteRepositoryInterface;

final class AddFavoriteUseCase
{
public function __construct(
private readonly FavoriteRepositoryInterface $favoriteRepository,
) {}

public function handle(int $userId, int $worldHeritageSiteId): void
{
$this->favoriteRepository->addFavorite($userId, $worldHeritageSiteId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Packages\Features\Tests\CommandUseCases;

use App\Packages\Domains\Favorite\Interface\FavoriteRepositoryInterface;
use App\Packages\Features\CommandUseCases\UseCase\Favorite\AddFavoriteUseCase;
use Exception;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;

class AddFavoriteUseCaseTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}

#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function test_handle_calls_repository_addFavorite_with_given_ids(): void
{
/** @var FavoriteRepositoryInterface|MockInterface $repository */
$repository = Mockery::mock(FavoriteRepositoryInterface::class);
$repository->shouldReceive('addFavorite')
->once()
->with(1, 2);

(new AddFavoriteUseCase($repository))->handle(1, 2);
}

public function test_handle_propagates_exception_when_user_not_found(): void
{
/** @var FavoriteRepositoryInterface|MockInterface $repository */
$repository = Mockery::mock(FavoriteRepositoryInterface::class);
$repository->shouldReceive('addFavorite')
->once()
->with(999999, 2)
->andThrow(new Exception('User not found.'));

$this->expectException(Exception::class);
$this->expectExceptionMessage('User not found.');

(new AddFavoriteUseCase($repository))->handle(999999, 2);
}
}
Loading