subDay(); $endDate = null; $etablissement = new ShopperEstablishmentCode('ETAB01'); $site = new ShopperSiteCode('SITE'); $service = new ShopperServiceCode('101'); // WHEN $entity = new Shopper( $id, $email, $matricule, 'Nom', 'Prenom', $startDate, $endDate, $etablissement, $site, $service ); // THEN expect($entity->id())->toBe($id) ->and($entity->email)->toBe($email) ->and($entity->matricule)->toBe($matricule) ->and($entity->nom)->toBe('Nom') ->and($entity->prenom)->toBe('Prenom') ->and($entity->startDate)->toBe($startDate) ->and($entity->endDate)->toBeNull() ->and($entity->etablissement)->toBe($etablissement) ->and($entity->site)->toBe($site) ->and($entity->service)->toBe($service) ->and($entity->isActive())->toBeTrue(); }); it('is inactive when endDate is in the past', function (): void { // GIVEN $endDate = CarbonImmutable::now()->subDay(); // WHEN $entity = new Shopper( new ShopperId(Uuid::uuid7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', 'Prenom', CarbonImmutable::now()->subDays(2), $endDate, new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101') ); // THEN expect($entity->isActive())->toBeFalse(); }); it('is active when endDate is in the future', function (): void { // GIVEN $endDate = CarbonImmutable::now()->addDay(); // WHEN $entity = new Shopper( new ShopperId(Uuid::uuid7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', 'Prenom', CarbonImmutable::now()->subDays(2), $endDate, new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101') ); // THEN expect($entity->isActive())->toBeTrue(); }); it('throws exception if nom is empty', function (): void { // WHEN $action = fn () => new Shopper( new ShopperId(Uuid::uuid7()), new Email('test@example.com'), new Matricule('1234567'), '', 'Prenom', CarbonImmutable::now()->subDays(2), null, new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101') ); // THEN expect($action)->toThrow(\DomainException::class, 'nom cannot be empty'); }); it('throws exception if prenom is empty', function (): void { // WHEN $action = fn () => new Shopper( new ShopperId(Uuid::uuid7()), new Email('test@example.com'), new Matricule('1234567'), 'Nom', '', CarbonImmutable::now()->subDays(2), null, new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101') ); // THEN expect($action)->toThrow(\DomainException::class, 'prenom cannot be empty'); }); });