CampaignFactory::hydrated( published: true, name: 'Campaign A', printAllAtOnce: false, couponCodes: $couponCodes, printRules: new PrintRules(maxPerCustomer: 1), ); it('finds a campaign by its code with paginated coupons', function () use ($makeCampaign): void { // GIVEN $campaign = $makeCampaign(); $pagination = Pagination::firstPage(); $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, couponsPagination: $pagination)); // 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->createdAt)->toEqual($campaign->createdAt()) ->and($result->updatedAt)->toEqual($campaign->updatedAt()) ->and($result->coupons->getItems())->toEqual($campaign->coupons->value) ->and($result->coupons->getTotal())->toBe(1) ->and($result->coupons->getPagination()->equals($pagination))->toBeTrue(); }); it('returns CampaignNotFound when the code is not found', function (): void { // GIVEN $pagination = Pagination::firstPage(); $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, couponsPagination: $pagination)); // WHEN / THEN expect($result)->toBeInstanceOf(CampaignNotFound::class); }); }); describe('find campaign use case assertions', function (): void { it('rejects an input of the wrong type', function (): void { // GIVEN $repository = \Mockery::mock(CampaignRepository::class); $useCase = new FindCampaign($repository); $invalidInput = new class () implements BaseInput { }; // WHEN $action = fn (): Output => $useCase->execute($invalidInput); // THEN expect($action)->toThrow(\InvalidArgumentException::class); }); });