64 lines
2 KiB
PHP
64 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Domain\Models\ValueObjects\SeoMetadata;
|
|
|
|
describe('SeoMetadata', function (): void {
|
|
it('creates a valid SeoMetadata instance', function (): void {
|
|
// GIVEN
|
|
$title = 'Titre Optimisé pour le Référencement Naturel';
|
|
$description = 'Description complète et détaillée expliquant la page pour le SEO.';
|
|
|
|
// WHEN
|
|
$seo = new SeoMetadata(title: $title, description: $description);
|
|
|
|
// THEN
|
|
expect($seo->title)->toBe($title)
|
|
->and($seo->description)->toBe($description);
|
|
});
|
|
|
|
it('throws when title is empty', function (): void {
|
|
// GIVEN
|
|
$emptyTitle = ' ';
|
|
$description = 'Description valide';
|
|
|
|
// WHEN
|
|
expect(fn () => new SeoMetadata(title: $emptyTitle, description: $description))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when title exceeds 255 characters', function (): void {
|
|
// GIVEN
|
|
$tooLongTitle = str_repeat('a', 256);
|
|
$description = 'Description valide';
|
|
|
|
// WHEN
|
|
expect(fn () => new SeoMetadata(title: $tooLongTitle, description: $description))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when description is empty', function (): void {
|
|
// GIVEN
|
|
$title = 'Titre valide';
|
|
$emptyDescription = ' ';
|
|
|
|
// WHEN
|
|
expect(fn () => new SeoMetadata(title: $title, description: $emptyDescription))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when description exceeds 500 characters', function (): void {
|
|
// GIVEN
|
|
$title = 'Titre valide';
|
|
$tooLongDescription = str_repeat('a', 501);
|
|
|
|
// WHEN
|
|
expect(fn () => new SeoMetadata(title: $title, description: $tooLongDescription))
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|