71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?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);
|
|
});
|
|
});
|