fix tests for accompanying period comments

This commit is contained in:
Julien Fastré 2022-02-11 13:36:35 +01:00
parent 199a441593
commit 9b4c350213
2 changed files with 16 additions and 12 deletions

View File

@ -1153,11 +1153,8 @@ class AccompanyingPeriod implements
$this->removeComment($this->pinnedComment); $this->removeComment($this->pinnedComment);
} }
if ($comment instanceof Comment) { if (null !== $this->pinnedComment) {
if (null !== $this->pinnedComment) { $this->addComment($this->pinnedComment);
$this->addComment($this->pinnedComment);
}
$this->addComment($comment);
} }
$this->pinnedComment = $comment; $this->pinnedComment = $comment;

View File

@ -129,20 +129,27 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertNull($period->getPinnedComment()); $this->assertNull($period->getPinnedComment());
$period->setPinnedComment($comment); $period->setPinnedComment($comment);
$this->assertSame($period->getPinnedComment(), $comment); $this->assertSame($period->getPinnedComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertNull($comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertEquals(0, count($period->getComments()));
$period->setPinnedComment($replacingComment); $period->setPinnedComment($replacingComment);
$this->assertSame($period->getPinnedComment(), $replacingComment); $this->assertSame($period->getPinnedComment(), $replacingComment);
$this->assertSame($period, $replacingComment->getAccompanyingPeriod()); $this->assertNull($replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertNull($comment->getAccompanyingPeriod()); $this->assertEquals(1, count($period->getComments()));
$this->assertContains($comment, $period->getComments());
$period->setPinnedComment(null); $period->setPinnedComment(null);
$this->assertNull($period->getPinnedComment()); $this->assertNull($period->getPinnedComment());
$this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertSame($period, $replacingComment->getAccompanyingPeriod());
$this->assertEquals(2, count($period->getComments()));
$this->assertContains($comment, $period->getComments());
$this->assertContains($replacingComment, $period->getComments());
} }
public function testRequestor() public function testRequestor()