Working state

This commit is contained in:
julien
2026-03-16 09:25:44 +01:00
parent b5a728e669
commit fd3f608059
24 changed files with 249 additions and 502 deletions

View File

@@ -110,6 +110,18 @@ final class PostServiceTest extends TestCase
}
/**
* getPostById() retourne l'article trouvé.
*/
public function testGetPostByIdReturnsPost(): void
{
$post = $this->makePost(7, 'Titre', 'slug-7');
$this->repository->expects($this->once())->method('findById')->with(7)->willReturn($post);
self::assertSame($post, $this->service->getPostById(7));
}
// ── createPost ─────────────────────────────────────────────────
/**
@@ -217,6 +229,42 @@ final class PostServiceTest extends TestCase
}
/**
* updatePost() lève NotFoundException si la ligne disparaît entre lecture et écriture.
*/
public function testUpdatePostThrowsWhenRepositoryUpdateAffectsZeroRows(): void
{
$post = $this->makePost(3, 'Titre courant', 'titre-courant', '<p>Ancien contenu</p>');
$this->repository->expects($this->once())->method('findById')->with(3)->willReturn($post);
$this->sanitizer->method('sanitize')->willReturn('<p>Contenu sûr</p>');
$this->repository->expects($this->once())->method('update')->with(3, $this->isInstanceOf(Post::class), 'titre-courant', null)->willReturn(0);
$this->expectException(NotFoundException::class);
$this->service->updatePost(3, 'Titre courant', '<p>Contenu</p>');
}
/**
* updatePost() normalise et rend unique un slug personnalisé.
*/
public function testUpdatePostUsesNormalizedUniqueCustomSlug(): void
{
$current = $this->makePost(4, 'Titre courant', 'ancien-slug', '<p>Ancien contenu</p>');
$this->repository->expects($this->once())->method('findById')->with(4)->willReturn($current);
$this->sanitizer->method('sanitize')->willReturn('<p>Contenu sûr</p>');
$this->repository->expects($this->exactly(2))
->method('slugExists')
->withAnyParameters()
->willReturnOnConsecutiveCalls(true, false);
$this->repository->expects($this->once())
->method('update')
->with(4, $this->isInstanceOf(Post::class), 'nouveau-slug-1', 2)
->willReturn(1);
$this->service->updatePost(4, 'Titre courant', '<p>Contenu</p>', ' Nouveau slug !! ', 2);
}
// ── Helpers ────────────────────────────────────────────────────
/**