Working state
This commit is contained in:
@@ -59,21 +59,6 @@ final class PostExtensionTest extends TestCase
|
||||
self::assertNull($this->call('post_thumbnail', $post));
|
||||
}
|
||||
|
||||
|
||||
public function testPostExcerptReturnsHtmlUnchangedWhenContentIsShortEnough(): void
|
||||
{
|
||||
$post = new Post(4, 'Titre', '<p><strong>Bonjour</strong> monde</p>', 'titre-4');
|
||||
|
||||
self::assertSame('<strong>Bonjour</strong> monde', $this->call('post_excerpt', $post, 50));
|
||||
}
|
||||
|
||||
public function testPostInitialsFallsBackToFirstRawCharacterWhenOnlyStopWordsRemain(): void
|
||||
{
|
||||
$post = new Post(5, 'de la', '<p>Contenu</p>', 'slug-5');
|
||||
|
||||
self::assertSame('D', $this->call('post_initials', $post));
|
||||
}
|
||||
|
||||
public function testPostInitialsUseMeaningfulWordsAndFallback(): void
|
||||
{
|
||||
$post = new Post(1, 'Article de Blog', '<p>Contenu</p>', 'slug');
|
||||
|
||||
@@ -159,7 +159,7 @@ final class PostRepositoryTest extends TestCase
|
||||
public function testFindRecentReturnsEmptyArray(): void
|
||||
{
|
||||
$stmt = $this->stmtForRead([]);
|
||||
$this->db->method('prepare')->willReturn($stmt);
|
||||
$this->db->expects($this->once())->method('prepare')->willReturn($stmt);
|
||||
|
||||
$this->assertSame([], $this->repository->findRecent(5));
|
||||
}
|
||||
@@ -170,7 +170,7 @@ final class PostRepositoryTest extends TestCase
|
||||
public function testFindRecentPassesLimitCorrectly(): void
|
||||
{
|
||||
$stmt = $this->stmtForRead([]);
|
||||
$this->db->method('prepare')->willReturn($stmt);
|
||||
$this->db->expects($this->once())->method('prepare')->willReturn($stmt);
|
||||
|
||||
$stmt->expects($this->once())
|
||||
->method('bindValue')
|
||||
|
||||
@@ -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 ────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user