2026-09-29 16:59:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\PictureMetadata;
|
|
|
|
|
|
|
|
|
|
describe('PictureMetadata Value Object', function () {
|
|
|
|
|
test('it can be instantiated with null values', function () {
|
|
|
|
|
// GIVEN & WHEN
|
|
|
|
|
$metadata = new PictureMetadata();
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($metadata->alt)->toBeNull()
|
|
|
|
|
->and($metadata->title)->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it can be instantiated with valid alt and title', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$alt = 'Belle image de chat';
|
|
|
|
|
$title = 'Un chat qui joue';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$metadata = new PictureMetadata(alt: $alt, title: $title);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($metadata->alt)->toBe($alt)
|
|
|
|
|
->and($metadata->title)->toBe($title);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when alt is empty string', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$invalidAlt = ' ';
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(alt: $invalidAlt))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot be empty when provided.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when alt is shorter than 4 characters', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shortAlt = 'abc';
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(alt: $shortAlt))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture alt must be at least 4 characters.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when alt exceeds 75 characters', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$longAlt = str_repeat('a', 76);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(alt: $longAlt))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot exceed 75 characters.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when title is empty string', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$invalidTitle = ' ';
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(title: $invalidTitle))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture title cannot be empty when provided.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when title is shorter than 4 characters', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$shortTitle = 'xyz';
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(title: $shortTitle))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture title must be at least 4 characters.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it throws when title exceeds 75 characters', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$longTitle = str_repeat('b', 76);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PictureMetadata(title: $longTitle))
|
2026-10-02 10:53:21 +02:00
|
|
|
->toThrow(\InvalidArgumentException::class, 'Picture title cannot exceed 75 characters.');
|
2026-09-29 16:59:07 +02:00
|
|
|
});
|
|
|
|
|
});
|