189 lines
5.3 KiB
PHP
189 lines
5.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\Entities;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Models\Entities\Shopper;
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('Shopper', function (): void {
|
|
it('can instantiate correctly and check active status (active)', function (): void {
|
|
// GIVEN
|
|
$id = new ShopperId(Uuid::uuid7());
|
|
$email = new Email('test@example.com');
|
|
$matricule = new Matricule('1234567');
|
|
$startDate = CarbonImmutable::now()->subDay();
|
|
$endDate = null;
|
|
|
|
// 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,
|
|
'Etablissement',
|
|
'Site',
|
|
'Service'
|
|
);
|
|
|
|
// 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,
|
|
'Etablissement',
|
|
'Site',
|
|
'Service'
|
|
);
|
|
|
|
// 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,
|
|
'Etablissement',
|
|
'Site',
|
|
'Service'
|
|
);
|
|
|
|
// 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,
|
|
'Etablissement',
|
|
'Site',
|
|
'Service'
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'prenom cannot be empty');
|
|
});
|
|
|
|
it('throws exception if etablissement is empty', function (): void {
|
|
// WHEN
|
|
$action = fn () => new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
null,
|
|
'',
|
|
'Site',
|
|
'Service'
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'etablissement cannot be empty');
|
|
});
|
|
|
|
it('throws exception if site is empty', function (): void {
|
|
// WHEN
|
|
$action = fn () => new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
null,
|
|
'Etablissement',
|
|
'',
|
|
'Service'
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'site cannot be empty');
|
|
});
|
|
|
|
it('throws exception if service is empty', function (): void {
|
|
// WHEN
|
|
$action = fn () => new Shopper(
|
|
new ShopperId(Uuid::uuid7()),
|
|
new Email('test@example.com'),
|
|
new Matricule('1234567'),
|
|
'Nom',
|
|
'Prenom',
|
|
CarbonImmutable::now()->subDays(2),
|
|
null,
|
|
'Etablissement',
|
|
'Site',
|
|
''
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'service cannot be empty');
|
|
});
|
|
});
|