id())->toBe($id) ->and($campaign->code)->toBe($code) ->and($campaign->name)->toBe($name) ->and($campaign->publication)->toBe($publication) ->and($campaign->printAllAtOnce)->toBe($printAllAtOnce) ->and($campaign->coupons)->toBe($coupons) ->and($campaign->brandCode)->toBe($brandCode) ->and($campaign->updatedAt)->toBeNull() ->and($campaign->updatedAt())->toBeNull(); }); it('creates a campaign without coupon', function (): void { // GIVEN $id = CampaignId::generate(); $code = new CampaignCode('Camp100'); $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = []; $brandCode = new BrandCode('AAA01'); // WHEN $campaign = Campaign::hydrate( $id, $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode, ); // THEN expect($campaign->coupons)->toBe([]); }); it('creates a coupon with an explicit updatedAt date', function (): void { // GIVEN $id = CampaignId::generate(); $code = new CampaignCode('Camp100'); $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), new CouponQuantity(100), Country::FRANCE, new WarningThresholdQuantity(100), new PrintRules(maxPerCustomer: 3) ) ]; $brandCode = new BrandCode('AAA01'); $updatedAt = new \DateTimeImmutable('2026-09-22 10:00:00', new \DateTimeZone('UTC')); // WHEN $campaign = Campaign::hydrate( $id, $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode, $updatedAt ); // THEN expect($campaign->updatedAt)->toBe($updatedAt) ->and($campaign->updatedAt())->toBe($updatedAt); }); it('creates a new campaign with a freshly generated id', function (): void { // GIVEN $code = new CampaignCode('Camp100'); $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), new CouponQuantity(100), Country::FRANCE, new WarningThresholdQuantity(100), new PrintRules(maxPerCustomer: 3) ) ]; $brandCode = new BrandCode('AAA01'); // WHEN $campaign = Campaign::create( $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode ); // THEN expect($campaign->id())->toBeInstanceOf(CampaignId::class) ->and($campaign->code)->toBe($code) ->and($campaign->name)->toBe($name) ->and($campaign->publication)->toBe($publication) ->and($campaign->printAllAtOnce)->toBe($printAllAtOnce) ->and($campaign->coupons)->toBe($coupons) ->and($campaign->brandCode)->toBe($brandCode) ->and($campaign->updatedAt)->toBeNull() ->and($campaign->updatedAt())->toBeNull(); }); it('generates a different id for each created campaign', function (): void { // GIVEN $code = new CampaignCode('Camp100'); $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), new CouponQuantity(100), Country::FRANCE, new WarningThresholdQuantity(100), new PrintRules(maxPerCustomer: 3) ) ]; $brandCode = new BrandCode('AAA01'); // WHEN $firstCampaign = Campaign::create( $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode ); $secondCampaign = Campaign::create( $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode ); // THEN expect($firstCampaign->id()->equals($secondCampaign->id()))->toBeFalse(); }); it('returns the creation date extracted from the id', function (): void { // GIVEN $expected = new \DateTimeImmutable('2024-06-15 12:34:56.789000', new \DateTimeZone('UTC')); $id = new CampaignId(Uuid::uuid7($expected)); $campaign = Campaign::hydrate( $id, new CampaignCode('Camp100'), new CampaignName('Name'), \boolval(0), \boolval(1), [ new CampaignCoupon( new ProcessingCode('PC1'), new CouponQuantity(100), Country::FRANCE, new WarningThresholdQuantity(100), new PrintRules(maxPerCustomer: 3) ) ], new BrandCode('AAA01') ); // WHEN $result = $campaign->createdAt(); // THEN expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v')); }); it('rejects a campaign with a non-coupon element', function (): void { // GIVEN $id = CampaignId::generate(); $code = new CampaignCode('Camp100'); $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = ['PC1']; $brandCode = new BrandCode('AAA01'); // WHEN / THEN expect(fn (): Campaign => Campaign::hydrate( $id, $code, $name, $publication, $printAllAtOnce, $coupons, $brandCode ))->toThrow(\DomainException::class, 'Campaign coupons must be CampaignCoupon instances.'); }); });