new Input(...array_merge([ 'name' => new CampaignName('Name'), 'brandCode' => new BrandCode('AAA01'), 'printAllAtOnce' => false, 'coupons' => new CampaignCouponArray([ new CampaignCoupon(new CouponCode('COU01'), new PrintRules(maxPerCustomer: 1)), new CampaignCoupon(new CouponCode('COU02'), new PrintRules(cooldownDays: 30)), ]), 'createdBy' => ActorId::generate(), ], $overrides)); it('creates a campaign when the name is unique', function () use ($makeInput): void { // GIVEN $input = $makeInput(); $repository = \Mockery::mock(CampaignRepository::class); $repository->shouldReceive('existsByName')->once()->with($input->name)->andReturn(false); $repository->shouldReceive('save')->once()->with(\Mockery::type(Campaign::class)); $useCase = new CreateCampaign($repository); // WHEN $result = $useCase->execute($input); // THEN expect($result)->toBeInstanceOf(CampaignCreated::class) ->and($result->code)->toBeInstanceOf(CampaignCode::class) ->and($result->name)->toEqual($input->name) ->and($result->publication)->toBeFalse() ->and($result->printAllAtOnce)->toBeFalse() ->and($result->brandCode)->toBeInstanceOf(BrandCode::class) ->and($result->brandCode)->toEqual($input->brandCode) ->and($result->actorId)->toEqual($input->createdBy) ->and($result->coupons)->toEqual($input->coupons); }); it('throws when the campaign name already exists', function () use ($makeInput): void { // GIVEN $input = $makeInput(); $repository = \Mockery::mock(CampaignRepository::class); $repository->shouldReceive('existsByName')->once()->with($input->name)->andReturn(true); $useCase = new CreateCampaign($repository); // WHEN $result = $useCase->execute($input); // THEN expect($result)->toBeInstanceOf(CampaignNameAlreadyExists::class); }); });