ldc-arcadia-api/tests/Unit/Domain/Models/ValueObjects/Inco/IngredientsTest.php

60 lines
1.6 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\Inco;
use Domain\Models\ValueObjects\Inco\Ingredients;
covers(Ingredients::class);
describe('Ingredients Value Object Instantiation', function (): void {
it('can be instantiated with ingredient groups', function (): void {
// GIVEN
$groups = [
'Ingrédients' => ['Viande de dinde (66%)', 'Eau', 'Sel'],
];
// WHEN
$ingredients = new Ingredients($groups);
// THEN
expect($ingredients->groups)->toBe($groups);
});
});
describe('Ingredients Value Object Domain Rules', function (): void {
it('throws DomainException for empty ingredient line', function (): void {
// GIVEN
$groups = [
'Ingrédients' => [' '],
];
// WHEN & THEN
expect(fn () => new Ingredients($groups))
->toThrow(\DomainException::class, 'string should not be empty');
});
it('throws DomainException for non-string ingredient line', function (): void {
// GIVEN
$groups = [
'Ingrédients' => [123],
];
// WHEN & THEN
expect(fn () => new Ingredients($groups))
->toThrow(\DomainException::class, 'value must be a string');
});
it('throw DomainException for non-array ingredient group', function (): void {
// GIVEN
$groups = [
'Ingrédients' => 'Viande de dinde (66%)',
];
// WHEN & THEN
expect(fn () => new Ingredients($groups))
->toThrow(\DomainException::class, 'value must be an array of strings');
});
});