ldc-boutique-cnc-sable/tests/Unit/Domain/Models/ValueObjects/AttachedFileTest.php

72 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\AttachedFile;
describe('AttachedFile', function () {
function getNewAttachedFile(array $overrides = []): AttachedFile
{
$data = array_merge([
'path' => 'path/to/file',
'originalName' => 'file.pdf',
'mimeType' => 'application/pdf',
], $overrides);
return new AttachedFile(...$data);
}
it('can instantiate', function () {
// GIVEN
$path = 'path/to/file';
$originalName = 'file.pdf';
$mimeType = 'application/pdf';
// WHEN
$vo = new AttachedFile(
path: $path,
originalName: $originalName,
mimeType: $mimeType
);
// THEN
expect($vo)->toBeInstanceOf(AttachedFile::class);
});
it('throws exception if path is empty', function () {
// GIVEN
$path = ' ';
// WHEN
$action = fn () => getNewAttachedFile(['path' => $path]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if original name is empty', function () {
// GIVEN
$originalName = ' ';
// WHEN
$action = fn () => getNewAttachedFile(['originalName' => $originalName]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if mime type is empty', function () {
// GIVEN
$mimeType = ' ';
// WHEN
$action = fn () => getNewAttachedFile(['mimeType' => $mimeType]);
// THEN
expect($action)->toThrow(\DomainException::class);
});
});