diff --git a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/SocialIssueConsistency/AccompanyingPeriodSocialIssueConsistencyEntityListenerTest.php b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/SocialIssueConsistency/AccompanyingPeriodSocialIssueConsistencyEntityListenerTest.php index 68100a1b3..81b65556f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/SocialIssueConsistency/AccompanyingPeriodSocialIssueConsistencyEntityListenerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/SocialIssueConsistency/AccompanyingPeriodSocialIssueConsistencyEntityListenerTest.php @@ -17,8 +17,12 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Event\PrePersistEventArgs; +use Doctrine\ORM\Event\PreUpdateEventArgs; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; /** * @internal @@ -26,6 +30,8 @@ use PHPUnit\Framework\TestCase; */ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends TestCase { + use ProphecyTrait; + public function testPrePersist() { $socialIssues = new ArrayCollection([ @@ -38,7 +44,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T $entity = $this->generateClass($period, $socialIssues); $consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener(); - $consistency->prePersist($entity, $this->generateLifecycleArgs()); + $consistency->prePersist($entity, $this->generateLifecycleArgs($period, Step::PrePersist)); $this->assertCount(2, $period->getSocialIssues()); $this->assertContains($grandGrandChild, $period->getSocialIssues()); @@ -63,7 +69,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T $period->addSocialIssue($issue); } - $consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs()); + $consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs($period, Step::PrePersist)); $this->assertCount(1, $period->getSocialIssues()); $this->assertSame($grandGrandChild, $period->getSocialIssues()->first()); @@ -81,7 +87,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T $entity = $this->generateClass($period, $socialIssues); $consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener(); - $consistency->preUpdate($entity, $this->generateLifecycleArgs()); + $consistency->preUpdate($entity, $this->generateLifecycleArgs($period, Step::PreUpdate)); $this->assertCount(2, $period->getSocialIssues()); $this->assertContains($grandGrandChild, $period->getSocialIssues()); @@ -106,7 +112,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T $period->addSocialIssue($issue); } - $consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs()); + $consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs($period, Step::PrePersist)); $this->assertCount(1, $period->getSocialIssues()); $this->assertSame($grandGrandChild, $period->getSocialIssues()->first()); @@ -138,8 +144,21 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T }; } - protected function generateLifecycleArgs(): LifecycleEventArgs + protected function generateLifecycleArgs(AccompanyingPeriod $period, Step $step): PrePersistEventArgs|PreUpdateEventArgs { - return $this->createMock(LifecycleEventArgs::class); + $entityManager = $this->prophesize(EntityManagerInterface::class); + + $dummyChanges = []; + + return match ($step) { + Step::PrePersist => new PrePersistEventArgs($period, $entityManager->reveal()), + Step::PreUpdate => new PreUpdateEventArgs($period, $entityManager->reveal(), $dummyChanges), + }; } } + +enum Step +{ + case PrePersist; + case PreUpdate; +}