Contenu

', 'ete-en-foret-2', 5, 'julien', 3, 'Tech', 'tech', $createdAt, $updatedAt, ); self::assertSame(10, $post->getId()); self::assertSame('Été en forêt', $post->getTitle()); self::assertSame('

Contenu

', $post->getContent()); self::assertSame('ete-en-foret-2', $post->getStoredSlug()); self::assertSame('ete-en-foret', $post->generateSlug()); self::assertSame(5, $post->getAuthorId()); self::assertSame('julien', $post->getAuthorUsername()); self::assertSame(3, $post->getCategoryId()); self::assertSame('Tech', $post->getCategoryName()); self::assertSame('tech', $post->getCategorySlug()); self::assertSame($createdAt, $post->getCreatedAt()); self::assertSame($updatedAt, $post->getUpdatedAt()); } public function testFromArrayHydratesOptionalFields(): void { $post = Post::fromArray([ 'id' => '7', 'title' => 'Titre', 'content' => '

Texte

', 'slug' => 'titre', 'author_id' => '9', 'author_username' => 'alice', 'category_id' => '2', 'category_name' => 'Actualités', 'category_slug' => 'actualites', 'created_at' => '2026-02-01 10:00:00', 'updated_at' => '2026-02-02 11:00:00', ]); self::assertSame(7, $post->getId()); self::assertSame('alice', $post->getAuthorUsername()); self::assertSame('Actualités', $post->getCategoryName()); self::assertSame('2026-02-01 10:00:00', $post->getCreatedAt()->format('Y-m-d H:i:s')); } public function testValidationRejectsEmptyTitle(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Le titre ne peut pas être vide'); new Post(1, '', '

Contenu

'); } public function testValidationRejectsTooLongTitle(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Le titre ne peut pas dépasser 255 caractères'); new Post(1, str_repeat('a', 256), '

Contenu

'); } public function testValidationRejectsEmptyContent(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Le contenu ne peut pas être vide'); new Post(1, 'Titre', ''); } public function testValidationRejectsTooLongContent(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Le contenu ne peut pas dépasser 65 535 caractères'); new Post(1, 'Titre', str_repeat('a', 65536)); } }