68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Shared\Models\ValueObjects;
|
|
|
|
use Shared\Models\ValueObjects\PicturePath;
|
|
|
|
covers(PicturePath::class);
|
|
|
|
describe('picture path', function (): void {
|
|
it('creates a valid PicturePath', function (): void {
|
|
// GIVEN
|
|
$pathValue = 'coupons/logo.png';
|
|
|
|
// WHEN
|
|
$path = new PicturePath($pathValue);
|
|
|
|
// THEN
|
|
expect($path)->toBeInstanceOf(PicturePath::class)
|
|
->and($path->value)->toBe($pathValue);
|
|
});
|
|
|
|
it('rejects an empty path', function (): void {
|
|
// GIVEN
|
|
$pathValue = '';
|
|
|
|
// WHEN
|
|
$action = fn (): PicturePath => new PicturePath($pathValue);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Picture Path cannot be empty.');
|
|
});
|
|
|
|
it('rejects a path that exceeds the maximum allowed length', function (): void {
|
|
// GIVEN
|
|
$pathValue = str_repeat('a', 210) . '.jpg';
|
|
|
|
// WHEN
|
|
$action = fn (): PicturePath => new PicturePath($pathValue);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Picture Path exceeds the maximum allowed length.');
|
|
});
|
|
|
|
it('accepts a path of exactly the maximum length', function (): void {
|
|
// GIVEN
|
|
$pathValue = str_repeat('a', 196) . '.jpg';
|
|
|
|
// WHEN
|
|
$path = new PicturePath($pathValue);
|
|
|
|
// THEN
|
|
expect($path)->toBeInstanceOf(PicturePath::class)
|
|
->and($path->value)->toHaveLength(200);
|
|
});
|
|
|
|
it('rejects a path without an image extension', function (): void {
|
|
// GIVEN
|
|
$pathValue = 'image';
|
|
|
|
// WHEN
|
|
$action = fn (): PicturePath => new PicturePath($pathValue);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Picture Path must end with one of: ' . implode(', ', PicturePath::ALLOWED_EXTENSIONS));
|
|
});
|
|
});
|