test that use case throws error if non existant user id given

This commit is contained in:
Yisroel Baum 2026-02-23 11:05:42 +02:00
parent 21da1a8991
commit f0eb4cf5d5
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 21 additions and 1 deletions

View file

@ -6,6 +6,7 @@ use App\Plan\CreatePlanDto;
use App\Plan\Plan;
use App\Plan\PlanRepository;
use App\User\UserRepository;
use DomainException;
class CreatePlan
{
@ -14,9 +15,17 @@ class CreatePlan
private UserRepository $userRepo,
) {}
/**
* @throws DomainException
*/
public function execute(CreatePlanRequest $request): Plan
{
$user = $this->userRepo->find($request->userId);
$userId = $request->userId;
$user = $this->userRepo->find($userId);
if ($user === null) {
throw new DomainException("User with id: $userId doesnt exist");
}
return $this->planRepo->create(new CreatePlanDto(
name: $request->name,