2026-08-14 11:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-08-14 15:38:10 +02:00
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Inco;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-14 15:38:10 +02:00
|
|
|
use Domain\Models\ValueObjects\Inco\Allergen;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
|
|
|
|
covers(Allergen::class);
|
|
|
|
|
|
|
|
|
|
describe('Allergen Value Object Instantiation', function (): void {
|
|
|
|
|
it('can be instantiated with positive code and label', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$code = 1;
|
|
|
|
|
$label = 'Gluten';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$allergen = new Allergen($code, $label);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($allergen->code)->toBe(1)
|
|
|
|
|
->and($allergen->label)->toBe('Gluten');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Allergen Value Object Domain Rules', function (): void {
|
|
|
|
|
it('throws DomainException for code <= 0', function (): void {
|
|
|
|
|
// GIVEN, WHEN & THEN
|
|
|
|
|
expect(fn () => new Allergen(0, 'Gluten'))
|
|
|
|
|
->toThrow(\DomainException::class, "Invalid code '0' shall be greater than 0");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws DomainException for empty label', function (): void {
|
|
|
|
|
// GIVEN, WHEN & THEN
|
|
|
|
|
expect(fn () => new Allergen(1, ' '))
|
|
|
|
|
->toThrow(\DomainException::class, "Invalid label ' ' should not be empty");
|
|
|
|
|
});
|
|
|
|
|
});
|