shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); $repository->shouldReceive('save')->once()->with(\Mockery::on( fn (CampaignRequest $saved): bool => $saved->status === CampaignRequestStatus::REJECTED && $saved->rejectionReason === $reason && $saved->updatedAt instanceof \DateTimeInterface, )); $useCase = new RejectCampaignRequest($repository); // WHEN $result = $useCase->execute(new Input(id: $id, reason: $reason)); // THEN expect($result)->toBeInstanceOf(CampaignRequestRejected::class) ->and($result->id)->toBe($id) ->and($result->status)->toBe(CampaignRequestStatus::REJECTED) ->and($result->rejectionReason)->toBe($reason) ->and($result->updatedAt->format('Y-m-d H:i:s'))->toBe('2026-06-15 12:00:00'); }); it('returns CampaignRequestNotFound when the id is not found', function (): void { // GIVEN $id = CampaignRequestId::generate(); $repository = \Mockery::mock(CampaignRequestRepository::class); $repository->shouldReceive('findById')->once()->with($id)->andReturn(null); $repository->shouldNotReceive('save'); $useCase = new RejectCampaignRequest($repository); // WHEN $result = $useCase->execute(new Input(id: $id, reason: new RejectionReason('Missing legal documents.'))); // THEN expect($result)->toBeInstanceOf(CampaignRequestNotFound::class); }); it('propagates the domain exception when the campaign request cannot be rejected', function () use ($requestedCoupon): void { // GIVEN $id = CampaignRequestId::generate(); $campaignRequest = CampaignRequest::hydrate( $id, new BrandCode('AAA01'), new CampaignName('Campaign A'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), CampaignRequestType::CLUB, $requestedCoupon, CampaignRequestStatus::TRANSFORMED, ); $repository = \Mockery::mock(CampaignRequestRepository::class); $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); $repository->shouldNotReceive('save'); $useCase = new RejectCampaignRequest($repository); // WHEN $action = fn (): Output => $useCase->execute( new Input(id: $id, reason: new RejectionReason('Missing legal documents.')) ); // THEN expect($action)->toThrow(\DomainException::class, 'Only a created campaign request can be rejected.'); }); });