From 8e95166c24120ca7e31622a55e34877340b81503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 18 May 2021 19:19:22 +0200 Subject: [PATCH] fix replacing an initial comment in accompanying period --- .../ChillPersonBundle/Entity/AccompanyingPeriod.php | 5 +++-- .../Tests/Entity/AccompanyingPeriodTest.php | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 91d4d6ef8..011199244 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -394,9 +394,10 @@ class AccompanyingPeriod */ public function setInitialComment(?Comment $comment = null): self { - if (NULL === $comment && NULL !== $this->initialComment) { + if (NULL !== $this->initialComment) { $this->removeComment($this->initialComment); - } elseif ($comment instanceof Comment) { + } + if ($comment instanceof Comment) { $this->addComment($comment); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php index b14f5180e..cd339bd70 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php @@ -137,6 +137,7 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase { $period = new AccompanyingPeriod(new \DateTime()); $comment = new Comment(); + $replacingComment = new Comment(); $period->setInitialComment(NULL); $this->assertNull($period->getInitialComment()); @@ -146,9 +147,15 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase $this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments"); + $period->setInitialComment($replacingComment); + $this->assertSame($period->getInitialComment(), $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()); + $period->setInitialComment(NULL); $this->assertNull($period->getInitialComment()); - $this->assertNull($comment->getAccompanyingPeriod()); + $this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments"); } }