Merge branch 'campaign' into 'common-sprint-2'

Campaign

See merge request ldc-web/projets/mesbr!31
This commit is contained in:
Karl M'muller 2026-09-22 12:03:39 +00:00
commit 173796c5fb
16 changed files with 929 additions and 0 deletions

View file

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Domain\Enums\Campaign;
use Shared\Enums\BaseEnum;
enum CampaignStatus: int
{
/** @use \Shared\Enums\BaseEnum<int> */
use BaseEnum;
case CREATED = 1;
case TRANSFORMED = 2;
case REJECTED = 3;
/**
* Optional labels definition
*
* @phpstan-ignore-next-line
*/
private const LABELS = [
self::CREATED->name => 'Crée',
self::TRANSFORMED->name => 'Transformé',
self::REJECTED->name => 'Rejeté'
];
}

View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Domain\Enums\Campaign;
use Shared\Enums\BaseEnum;
enum CampaignType: int
{
/** @use \Shared\Enums\BaseEnum<int> */
use BaseEnum;
case CLUB = 1;
case GAME = 2;
/**
* Optional labels definition
*
* @phpstan-ignore-next-line
*/
private const LABELS = [
self::CLUB->name => 'CLUB',
self::GAME->name => 'GAME',
];
}

View file

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace Domain\Models\Entities;
use Domain\Enums\Campaign\CampaignStatus;
use Domain\Enums\Campaign\CampaignType;
use Domain\Enums\Country;
use Domain\Models\ValueObjects\Brand\BrandCode;
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
use Domain\Models\ValueObjects\PrintRules;
use Shared\DDD\Models\AggregateRoot;
use Shared\DDD\Models\HasTimestampIdentifier;
/**
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId>
*/
final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdentifier
{
private function __construct(
public CampaignRequestId $id,
public BrandCode $code,
public Applicant $applicant,
public Country $country,
public CampaignType $campaignType,
public ?PrintRules $printRules,
public RequestedCoupon $requestedCoupon,
public CampaignStatus $status,
public ?\DateTimeInterface $updatedAt = null,
) {}
public function id(): CampaignRequestId
{
return $this->id;
}
public function createdAt(): \DateTimeInterface
{
return $this->id->toDateTime();
}
public function updatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public static function hydrate(
CampaignRequestId $id,
BrandCode $code,
Applicant $applicant,
Country $country,
CampaignType $campaignType,
?PrintRules $printRules,
RequestedCoupon $requestedCoupon,
CampaignStatus $status,
?\DateTimeInterface $updatedAt = null,
): self {
return new self(
id: $id,
code: $code,
applicant: $applicant,
country: $country,
campaignType: $campaignType,
printRules: $printRules,
requestedCoupon: $requestedCoupon,
status: $status,
updatedAt: $updatedAt,
);
}
}

View file

@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Domain\Models\Entities;
use Domain\Models\ValueObjects\Coupon\CouponValidity;
use Domain\Models\ValueObjects\CouponName;
use Domain\Models\ValueObjects\CouponPicture;
use Domain\Models\ValueObjects\CouponProductName;
use Domain\Models\ValueObjects\GS1;
use Domain\Models\ValueObjects\MoneyAmount;
use Domain\Models\ValueObjects\Period;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponId;
use Shared\DDD\Models\AggregateRoot;
use Shared\DDD\Models\HasTimestampIdentifier;
/**
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponId>
*/
final readonly class RequestedCoupon implements AggregateRoot, HasTimestampIdentifier
{
private function __construct(
public RequestedCouponId $id,
public CouponName $name,
public CouponProductName $productName,
public int $quantity,
public int $warningThresholdQuantity,
public Period $period,
public MoneyAmount $moneyAmount,
public ProcessingCode $processingCode,
public CouponPicture $couponPicture,
public GS1 $gs1,
public CouponValidity $couponValidity,
public ?\DateTimeInterface $updatedAt = null,
) {
}
public function id(): RequestedCouponId
{
return $this->id;
}
public function createdAt(): \DateTimeInterface
{
return $this->id->toDateTime();
}
public function updatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public static function hydrate(
RequestedCouponId $id,
CouponName $name,
CouponProductName $productName,
int $quantity,
int $warningThresholdQuantity,
Period $period,
MoneyAmount $moneyAmount,
ProcessingCode $processingCode,
CouponPicture $couponPicture,
GS1 $gs1,
CouponValidity $couponValidity,
?\DateTimeInterface $updatedAt = null,
): self {
return new self(
id: $id,
name: $name,
productName: $productName,
quantity: $quantity,
warningThresholdQuantity: $warningThresholdQuantity,
period: $period,
moneyAmount: $moneyAmount,
processingCode: $processingCode,
couponPicture: $couponPicture,
gs1: $gs1,
couponValidity: $couponValidity,
updatedAt: $updatedAt,
);
}
}

View file

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects\CampaignRequest;
use Shared\ValueObjects\Email;
final readonly class Applicant
{
public function __construct(
public string $firstname,
public string $lastname,
public Email $email,
) {
$trimmedFirstname = trim($firstname);
if ($trimmedFirstname === '') {
throw new \DomainException('Applicant firstname cannot be empty.');
}
if (mb_strlen($trimmedFirstname) > 200) {
throw new \DomainException('Applicant firstname exceeds the maximum allowed length.');
}
$trimmedLastname = trim($lastname);
if ($trimmedLastname === '') {
throw new \DomainException('Applicant lastname cannot be empty.');
}
if (mb_strlen($trimmedLastname) > 200) {
throw new \DomainException('Applicant lastname exceeds the maximum allowed length.');
}
}
}

View file

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects\CampaignRequest;
use Ramsey\Uuid\Uuid;
use Shared\DDD\Models\Uuidv7EntityId;
final readonly class CampaignRequestId extends Uuidv7EntityId
{
public static function generate(): static
{
return new self(Uuid::uuid7());
}
}

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
final readonly class PrintRules
{
public function __construct(
public ?int $maxPerCustomer = null,
public ?int $cooldownDays = null,
) {
}
}

View file

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects\RequestedCoupon;
use Ramsey\Uuid\Uuid;
use Shared\DDD\Models\Uuidv7EntityId;
final readonly class RequestedCouponId extends Uuidv7EntityId
{
public static function generate(): static
{
return new self(Uuid::uuid7());
}
}

View file

@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Enums\Campaign;
use Domain\Enums\Campaign\CampaignStatus;
covers(CampaignStatus::class);
describe('campaign status', function (): void {
it('has the expected cases with their backing values', function (): void {
// THEN
expect(CampaignStatus::CREATED->value())->toBe(1)
->and(CampaignStatus::TRANSFORMED->value())->toBe(2)
->and(CampaignStatus::REJECTED->value())->toBe(3);
});
it('exposes its case name', function (): void {
// THEN
expect(CampaignStatus::CREATED->name())->toBe('CREATED');
});
it('returns the defined label', function (): void {
// THEN
expect(CampaignStatus::CREATED->label())->toBe('Crée')
->and(CampaignStatus::TRANSFORMED->label())->toBe('Transformé')
->and(CampaignStatus::REJECTED->label())->toBe('Rejeté');
});
it('lists all labels keyed by case name', function (): void {
// THEN
expect(CampaignStatus::toLabels())->toBe([
'CREATED' => 'Crée',
'TRANSFORMED' => 'Transformé',
'REJECTED' => 'Rejeté',
]);
});
it('lists all values keyed by case name', function (): void {
// THEN
expect(CampaignStatus::toValues())->toBe([
'CREATED' => 1,
'TRANSFORMED' => 2,
'REJECTED' => 3,
]);
});
it('makes an instance from its backing value', function (): void {
// THEN
expect(CampaignStatus::make(1))->toBe(CampaignStatus::CREATED);
});
it('makes an instance from a label', function (): void {
// THEN
expect(CampaignStatus::make('Transformé', 'label'))->toBe(CampaignStatus::TRANSFORMED);
});
it('returns the same instance when already an enum case', function (): void {
// THEN
expect(CampaignStatus::make(CampaignStatus::REJECTED))->toBe(CampaignStatus::REJECTED);
});
it('returns null for an unknown value', function (): void {
// THEN
expect(CampaignStatus::make(99))->toBeNull();
});
it('implements equals correctly', function (): void {
// THEN
expect(CampaignStatus::CREATED->equals(CampaignStatus::CREATED))->toBeTrue()
->and(CampaignStatus::CREATED->equals(CampaignStatus::REJECTED))->toBeFalse()
->and(CampaignStatus::CREATED->equals(null))->toBeFalse();
});
it('serializes to json as its backing value', function (): void {
// THEN
expect(CampaignStatus::CREATED->jsonSerialize())->toBe(1)
->and(json_encode(CampaignStatus::CREATED))->toBe('1');
});
});

View file

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Enums\Campaign;
use Domain\Enums\Campaign\CampaignType;
covers(CampaignType::class);
describe('campaign type', function (): void {
it('has the expected cases with their backing values', function (): void {
// THEN
expect(CampaignType::CLUB->value())->toBe(1)
->and(CampaignType::GAME->value())->toBe(2);
});
it('exposes its case name', function (): void {
// THEN
expect(CampaignType::CLUB->name())->toBe('CLUB');
});
it('returns the defined label', function (): void {
// THEN
expect(CampaignType::CLUB->label())->toBe('CLUB')
->and(CampaignType::GAME->label())->toBe('GAME');
});
it('lists all labels keyed by case name', function (): void {
// THEN
expect(CampaignType::toLabels())->toBe([
'CLUB' => 'CLUB',
'GAME' => 'GAME',
]);
});
it('lists all values keyed by case name', function (): void {
// THEN
expect(CampaignType::toValues())->toBe([
'CLUB' => 1,
'GAME' => 2,
]);
});
it('makes an instance from its backing value', function (): void {
// THEN
expect(CampaignType::make(1))->toBe(CampaignType::CLUB);
});
it('makes an instance from a label', function (): void {
// THEN
expect(CampaignType::make('GAME', 'label'))->toBe(CampaignType::GAME);
});
it('returns the same instance when already an enum case', function (): void {
// THEN
expect(CampaignType::make(CampaignType::CLUB))->toBe(CampaignType::CLUB);
});
it('returns null for an unknown value', function (): void {
// THEN
expect(CampaignType::make(99))->toBeNull();
});
it('implements equals correctly', function (): void {
// THEN
expect(CampaignType::CLUB->equals(CampaignType::CLUB))->toBeTrue()
->and(CampaignType::CLUB->equals(CampaignType::GAME))->toBeFalse()
->and(CampaignType::CLUB->equals(null))->toBeFalse();
});
it('serializes to json as its backing value', function (): void {
// THEN
expect(CampaignType::CLUB->jsonSerialize())->toBe(1)
->and(json_encode(CampaignType::CLUB))->toBe('1');
});
});

View file

@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities;
use Carbon\CarbonImmutable;
use Domain\Enums\BarcodeFormat;
use Domain\Enums\Campaign\CampaignStatus;
use Domain\Enums\Campaign\CampaignType;
use Domain\Enums\Country;
use Domain\Models\Entities\CampaignRequest;
use Domain\Models\Entities\RequestedCoupon;
use Domain\Models\ValueObjects\Brand\BrandCode;
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
use Domain\Models\ValueObjects\Coupon\CouponValidity;
use Domain\Models\ValueObjects\CouponName;
use Domain\Models\ValueObjects\CouponPicture;
use Domain\Models\ValueObjects\CouponProductName;
use Domain\Models\ValueObjects\GS1;
use Domain\Models\ValueObjects\MoneyAmount;
use Domain\Models\ValueObjects\Period;
use Domain\Models\ValueObjects\PicturePath;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponId;
use Ramsey\Uuid\Uuid;
use Shared\Enums\Currency;
use Shared\ValueObjects\DateTime;
use Shared\ValueObjects\Email;
use Shared\ValueObjects\Money;
covers(CampaignRequest::class);
function aRequestedCoupon(): RequestedCoupon
{
return RequestedCoupon::hydrate(
RequestedCouponId::generate(),
new CouponName('Coupon A'),
new CouponProductName('Product A'),
100,
10,
new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')),
new MoneyAmount(new Money(Currency::EUR, 300)),
new ProcessingCode('PC1'),
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, DateTime::now()),
);
}
describe('campaign request', function (): void {
afterEach(function (): void {
CarbonImmutable::setTestNow();
});
it('hydrates a campaign request with all its fields', function (): void {
// GIVEN
$id = CampaignRequestId::generate();
$code = new BrandCode('AAA01');
$applicant = new Applicant('John', 'Doe', new Email('john.doe@example.com'));
$country = Country::FR;
$campaignType = CampaignType::CLUB;
$printRules = new PrintRules(maxPerCustomer: 3);
$requestedCoupon = aRequestedCoupon();
$status = CampaignStatus::CREATED;
// WHEN
$campaignRequest = CampaignRequest::hydrate(
$id,
$code,
$applicant,
$country,
$campaignType,
$printRules,
$requestedCoupon,
$status,
);
// THEN
expect($campaignRequest->id())->toBe($id)
->and($campaignRequest->code)->toBe($code)
->and($campaignRequest->applicant)->toBe($applicant)
->and($campaignRequest->country)->toBe($country)
->and($campaignRequest->campaignType)->toBe($campaignType)
->and($campaignRequest->printRules)->toBe($printRules)
->and($campaignRequest->requestedCoupon)->toBe($requestedCoupon)
->and($campaignRequest->status)->toBe($status)
->and($campaignRequest->updatedAt)->toBeNull()
->and($campaignRequest->updatedAt())->toBeNull();
});
it('hydrates a campaign request with a null printRules', function (): void {
// WHEN
$campaignRequest = CampaignRequest::hydrate(
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
Country::FR,
CampaignType::CLUB,
null,
aRequestedCoupon(),
CampaignStatus::CREATED,
);
// THEN
expect($campaignRequest->printRules)->toBeNull();
});
it('hydrates a campaign request with an explicit updatedAt date', function (): void {
// GIVEN
$updatedAt = new \DateTimeImmutable('2026-06-15 12:00:00', new \DateTimeZone('UTC'));
// WHEN
$campaignRequest = CampaignRequest::hydrate(
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
Country::FR,
CampaignType::CLUB,
new PrintRules(maxPerCustomer: 3),
aRequestedCoupon(),
CampaignStatus::CREATED,
$updatedAt,
);
// THEN
expect($campaignRequest->updatedAt)->toBe($updatedAt)
->and($campaignRequest->updatedAt())->toBe($updatedAt);
});
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 CampaignRequestId(Uuid::uuid7($expected));
$campaignRequest = CampaignRequest::hydrate(
$id,
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
Country::FR,
CampaignType::CLUB,
new PrintRules(maxPerCustomer: 3),
aRequestedCoupon(),
CampaignStatus::CREATED,
);
// WHEN
$result = $campaignRequest->createdAt();
// THEN
expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v'));
});
});

View file

@ -0,0 +1,126 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities;
use Carbon\CarbonImmutable;
use Domain\Enums\BarcodeFormat;
use Domain\Models\Entities\RequestedCoupon;
use Domain\Models\ValueObjects\Coupon\CouponValidity;
use Domain\Models\ValueObjects\CouponName;
use Domain\Models\ValueObjects\CouponPicture;
use Domain\Models\ValueObjects\CouponProductName;
use Domain\Models\ValueObjects\GS1;
use Domain\Models\ValueObjects\MoneyAmount;
use Domain\Models\ValueObjects\Period;
use Domain\Models\ValueObjects\PicturePath;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponId;
use Ramsey\Uuid\Uuid;
use Shared\Enums\Currency;
use Shared\ValueObjects\DateTime;
use Shared\ValueObjects\Money;
covers(RequestedCoupon::class);
describe('requested coupon', function (): void {
afterEach(function (): void {
CarbonImmutable::setTestNow();
});
it('hydrates a requested coupon with all its fields', function (): void {
// GIVEN
$id = RequestedCouponId::generate();
$name = new CouponName('Coupon A');
$productName = new CouponProductName('Product A');
$quantity = 100;
$warningThresholdQuantity = 10;
$period = new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01'));
$moneyAmount = new MoneyAmount(new Money(Currency::EUR, 300));
$processingCode = new ProcessingCode('PC1');
$couponPicture = new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg'));
$gs1 = new GS1('01234567890128', BarcodeFormat::EAN13);
$couponValidity = new CouponValidity(30, DateTime::now());
// WHEN
$coupon = RequestedCoupon::hydrate(
$id,
$name,
$productName,
$quantity,
$warningThresholdQuantity,
$period,
$moneyAmount,
$processingCode,
$couponPicture,
$gs1,
$couponValidity,
);
// THEN
expect($coupon->id())->toBe($id)
->and($coupon->name)->toBe($name)
->and($coupon->productName)->toBe($productName)
->and($coupon->quantity)->toBe($quantity)
->and($coupon->warningThresholdQuantity)->toBe($warningThresholdQuantity)
->and($coupon->period)->toBe($period)
->and($coupon->moneyAmount)->toBe($moneyAmount)
->and($coupon->processingCode)->toBe($processingCode)
->and($coupon->couponPicture)->toBe($couponPicture)
->and($coupon->gs1)->toBe($gs1)
->and($coupon->couponValidity)->toBe($couponValidity)
->and($coupon->updatedAt)->toBeNull()
->and($coupon->updatedAt())->toBeNull();
});
it('hydrates a requested coupon with an explicit updatedAt date', function (): void {
// GIVEN
$updatedAt = new \DateTimeImmutable('2026-06-15 12:00:00', new \DateTimeZone('UTC'));
// WHEN
$coupon = RequestedCoupon::hydrate(
RequestedCouponId::generate(),
new CouponName('Coupon A'),
new CouponProductName('Product A'),
100,
10,
new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')),
new MoneyAmount(new Money(Currency::EUR, 300)),
new ProcessingCode('PC1'),
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, DateTime::now()),
$updatedAt,
);
// THEN
expect($coupon->updatedAt)->toBe($updatedAt)
->and($coupon->updatedAt())->toBe($updatedAt);
});
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 RequestedCouponId(Uuid::uuid7($expected));
$coupon = RequestedCoupon::hydrate(
$id,
new CouponName('Coupon A'),
new CouponProductName('Product A'),
100,
10,
new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')),
new MoneyAmount(new Money(Currency::EUR, 300)),
new ProcessingCode('PC1'),
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, DateTime::now()),
);
// WHEN
$result = $coupon->createdAt();
// THEN
expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v'));
});
});

View file

@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\CampaignRequest;
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
use Shared\ValueObjects\Email;
covers(Applicant::class);
describe('applicant', function (): void {
it('creates a valid applicant', function (): void {
// GIVEN
$firstname = 'John';
$lastname = 'Doe';
$email = new Email('john.doe@example.com');
// WHEN
$applicant = new Applicant($firstname, $lastname, $email);
// THEN
expect($applicant)->toBeInstanceOf(Applicant::class)
->and($applicant->firstname)->toBe($firstname)
->and($applicant->lastname)->toBe($lastname)
->and($applicant->email)->toBe($email);
});
it('rejects an empty or whitespace-only firstname', function (string $firstname): void {
// WHEN
$action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant firstname cannot be empty.');
})->with([
'empty' => '',
'spaces' => ' ',
]);
it('rejects a firstname that exceeds the maximum allowed length', function (): void {
// GIVEN
$firstname = str_repeat('a', 201);
// WHEN
$action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant firstname exceeds the maximum allowed length.');
});
it('accepts a firstname of exactly the maximum length', function (): void {
// GIVEN
$firstname = str_repeat('a', 200);
// WHEN
$applicant = new Applicant($firstname, 'Doe', new Email('john.doe@example.com'));
// THEN
expect(mb_strlen($applicant->firstname))->toBe(200);
});
it('rejects an empty or whitespace-only lastname', function (string $lastname): void {
// WHEN
$action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant lastname cannot be empty.');
})->with([
'empty' => '',
'spaces' => ' ',
]);
it('rejects a lastname that exceeds the maximum allowed length', function (): void {
// GIVEN
$lastname = str_repeat('a', 201);
// WHEN
$action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect($action)->toThrow(\DomainException::class, 'Applicant lastname exceeds the maximum allowed length.');
});
it('accepts a lastname of exactly the maximum length', function (): void {
// GIVEN
$lastname = str_repeat('a', 200);
// WHEN
$applicant = new Applicant('John', $lastname, new Email('john.doe@example.com'));
// THEN
expect(mb_strlen($applicant->lastname))->toBe(200);
});
});

View file

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\CampaignRequest;
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
covers(CampaignRequestId::class);
describe('campaign request id', function (): void {
it('generates a unique campaign request id', function (): void {
// WHEN
$id = CampaignRequestId::generate();
// THEN
expect($id)->toBeInstanceOf(CampaignRequestId::class);
});
it('generates different ids on each call', function (): void {
// WHEN
$first = CampaignRequestId::generate();
$second = CampaignRequestId::generate();
// THEN
expect((string) $first)->not->toBe((string) $second);
});
});

View file

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\PrintRules;
covers(PrintRules::class);
describe('print rules', function (): void {
it('creates print rules with both fields set', function (): void {
// WHEN
$printRules = new PrintRules(maxPerCustomer: 3, cooldownDays: 30);
// THEN
expect($printRules)->toBeInstanceOf(PrintRules::class)
->and($printRules->maxPerCustomer)->toBe(3)
->and($printRules->cooldownDays)->toBe(30);
});
it('creates print rules with only maxPerCustomer set', function (): void {
// WHEN
$printRules = new PrintRules(maxPerCustomer: 5);
// THEN
expect($printRules->maxPerCustomer)->toBe(5)
->and($printRules->cooldownDays)->toBeNull();
});
it('creates print rules with only cooldownDays set', function (): void {
// WHEN
$printRules = new PrintRules(cooldownDays: 45);
// THEN
expect($printRules->maxPerCustomer)->toBeNull()
->and($printRules->cooldownDays)->toBe(45);
});
it('creates print rules with both fields null by default', function (): void {
// WHEN
$printRules = new PrintRules();
// THEN
expect($printRules->maxPerCustomer)->toBeNull()
->and($printRules->cooldownDays)->toBeNull();
});
});

View file

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponId;
covers(RequestedCouponId::class);
describe('requested coupon id', function (): void {
it('generates a unique requested coupon id', function (): void {
// WHEN
$id = RequestedCouponId::generate();
// THEN
expect($id)->toBeInstanceOf(RequestedCouponId::class);
});
it('generates different ids on each call', function (): void {
// WHEN
$first = RequestedCouponId::generate();
$second = RequestedCouponId::generate();
// THEN
expect((string) $first)->not->toBe((string) $second);
});
});