ldc-mesbr-app/tests/Unit/Shared/Models/ValueObjects/PicturePathTest.php

69 lines
1.9 KiB
PHP
Raw Normal View History

2026-07-24 17:19:56 +02:00
<?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);
2026-07-24 17:19:56 +02:00
});
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.');
2026-07-24 17:19:56 +02:00
});
it('rejects a path that exceeds the maximum allowed length', function (): void {
// GIVEN
$pathValue = str_repeat('a', 210) . '.jpg';
2026-07-24 17:19:56 +02:00
// WHEN
$action = fn (): PicturePath => new PicturePath($pathValue);
// THEN
expect($action)->toThrow(\DomainException::class, 'Picture Path exceeds the maximum allowed length.');
2026-07-24 17:19:56 +02:00
});
it('accepts a path of exactly the maximum length', function (): void {
// GIVEN
$pathValue = str_repeat('a', 196) . '.jpg';
2026-07-24 17:19:56 +02:00
// WHEN
$path = new PicturePath($pathValue);
// THEN
expect($path)->toBeInstanceOf(PicturePath::class)
->and($path->value)->toHaveLength(200);
2026-07-24 17:19:56 +02:00
});
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));
2026-07-24 17:19:56 +02:00
});
});