diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 593cdfc83..1e7444af6 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -1153,11 +1153,8 @@ class AccompanyingPeriod implements $this->removeComment($this->pinnedComment); } - if ($comment instanceof Comment) { - if (null !== $this->pinnedComment) { - $this->addComment($this->pinnedComment); - } - $this->addComment($comment); + if (null !== $this->pinnedComment) { + $this->addComment($this->pinnedComment); } $this->pinnedComment = $comment; diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php index a459c3c18..6c78d817d 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php @@ -129,20 +129,27 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase $this->assertNull($period->getPinnedComment()); $period->setPinnedComment($comment); + $this->assertSame($period->getPinnedComment(), $comment); - $this->assertSame($period, $comment->getAccompanyingPeriod()); - $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); + $this->assertNull($comment->getAccompanyingPeriod()); + $this->assertEquals(0, count($period->getComments())); $period->setPinnedComment($replacingComment); + $this->assertSame($period->getPinnedComment(), $replacingComment); - $this->assertSame($period, $replacingComment->getAccompanyingPeriod()); - $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); - $this->assertNull($comment->getAccompanyingPeriod()); + $this->assertNull($replacingComment->getAccompanyingPeriod()); + $this->assertSame($period, $comment->getAccompanyingPeriod()); + $this->assertEquals(1, count($period->getComments())); + $this->assertContains($comment, $period->getComments()); $period->setPinnedComment(null); + $this->assertNull($period->getPinnedComment()); - $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->assertSame($period, $replacingComment->getAccompanyingPeriod()); + $this->assertEquals(2, count($period->getComments())); + $this->assertContains($comment, $period->getComments()); + $this->assertContains($replacingComment, $period->getComments()); } public function testRequestor()