ldc-boutique-cnc-sable/tests/Unit/Domain/Models/ValueObjects/PictureMetadataTest.php
Jérémy Munsch 3398aacc86
refactor(casts): update exception handling to use fully qualified class names
Refactored exception handling in various cast classes to use fully qualified class names for InvalidArgumentException and UnexpectedValueException.
2026-10-27 09:58:45 +01:00

83 lines
2.6 KiB
PHP

<?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))
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot be empty when provided.');
});
test('it throws when alt is shorter than 4 characters', function () {
// GIVEN
$shortAlt = 'abc';
// WHEN & THEN
expect(fn () => new PictureMetadata(alt: $shortAlt))
->toThrow(\InvalidArgumentException::class, 'Picture alt must be at least 4 characters.');
});
test('it throws when alt exceeds 75 characters', function () {
// GIVEN
$longAlt = str_repeat('a', 76);
// WHEN & THEN
expect(fn () => new PictureMetadata(alt: $longAlt))
->toThrow(\InvalidArgumentException::class, 'Picture alt cannot exceed 75 characters.');
});
test('it throws when title is empty string', function () {
// GIVEN
$invalidTitle = ' ';
// WHEN & THEN
expect(fn () => new PictureMetadata(title: $invalidTitle))
->toThrow(\InvalidArgumentException::class, 'Picture title cannot be empty when provided.');
});
test('it throws when title is shorter than 4 characters', function () {
// GIVEN
$shortTitle = 'xyz';
// WHEN & THEN
expect(fn () => new PictureMetadata(title: $shortTitle))
->toThrow(\InvalidArgumentException::class, 'Picture title must be at least 4 characters.');
});
test('it throws when title exceeds 75 characters', function () {
// GIVEN
$longTitle = str_repeat('b', 76);
// WHEN & THEN
expect(fn () => new PictureMetadata(title: $longTitle))
->toThrow(\InvalidArgumentException::class, 'Picture title cannot exceed 75 characters.');
});
});