ldc-cocotte/tests/Unit/Domain/Models/ValueObjects/AttachedFileTest.php

73 lines
1.9 KiB
PHP
Raw 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 () {
/** @param array{path?: string, originalName?: string, mimeType?: string} $overrides */
2026-06-14 21:32:07 +02:00
function getNewAttachedFile(array $overrides = []): AttachedFile
{
return new AttachedFile(
path: $overrides['path'] ?? 'path/to/file',
originalName: $overrides['originalName'] ?? 'file.pdf',
mimeType: $overrides['mimeType'] ?? 'application/pdf',
);
2026-06-14 21:32:07 +02:00
}
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->path)->toBe($path)
->and($vo->originalName)->toBe($originalName)
->and($vo->mimeType)->toBe($mimeType);
2026-06-14 21:32:07 +02:00
});
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);
});
});