CampaignFactory::hydrated( published: true, name: 'Campaign A', printAllAtOnce: false, couponCodes: $couponCodes ?? [$couponCode], printRules: new PrintRules(maxPerCustomer: 1), ); it('finds a campaign by its code with coupons array', function () use ($makeCampaign, $couponCode): void { // GIVEN $campaign = $makeCampaign(); $repository = \Mockery::mock(CampaignRepository::class); $repository->shouldReceive('findByCode')->once()->with($campaign->code)->andReturn($campaign); $useCase = new FindCampaign($repository); // WHEN $result = $useCase->execute(new Input(code: $campaign->code)); // THEN expect($result)->toBeInstanceOf(CampaignFound::class) ->and($result->name)->toBe($campaign->name) ->and($result->code)->toBe($campaign->code) ->and($result->brandCode)->toBe($campaign->brandCode) ->and($result->publication)->toBe($campaign->publication) ->and($result->printAllAtOnce)->toBe($campaign->printAllAtOnce) ->and($result->coupons)->toBe($campaign->coupons) ->and($result->coupons->toArray()[0]->couponCode->value)->toBe($couponCode->value) ->and($result->createdAt)->toEqual($campaign->createdAt()) ->and($result->updatedAt)->toEqual($campaign->updatedAt()); }); it('returns CampaignNotFound when the code is not found', function (): void { // GIVEN $code = CampaignCode::generate(); $repository = \Mockery::mock(CampaignRepository::class); $repository->shouldReceive('findByCode')->once()->with($code)->andReturn(null); $useCase = new FindCampaign($repository); // WHEN $result = $useCase->execute(new Input(code: $code)); // WHEN / THEN expect($result)->toBeInstanceOf(CampaignNotFound::class); }); });