mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix deprecated lifecycleEvent to eventArgs in test
This commit is contained in:
parent
84dbfabd66
commit
5136907d62
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user