mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +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 Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||||
|
use Doctrine\ORM\Event\PrePersistEventArgs;
|
||||||
|
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -26,6 +30,8 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends TestCase
|
final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
public function testPrePersist()
|
public function testPrePersist()
|
||||||
{
|
{
|
||||||
$socialIssues = new ArrayCollection([
|
$socialIssues = new ArrayCollection([
|
||||||
@ -38,7 +44,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T
|
|||||||
$entity = $this->generateClass($period, $socialIssues);
|
$entity = $this->generateClass($period, $socialIssues);
|
||||||
$consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener();
|
$consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener();
|
||||||
|
|
||||||
$consistency->prePersist($entity, $this->generateLifecycleArgs());
|
$consistency->prePersist($entity, $this->generateLifecycleArgs($period, Step::PrePersist));
|
||||||
|
|
||||||
$this->assertCount(2, $period->getSocialIssues());
|
$this->assertCount(2, $period->getSocialIssues());
|
||||||
$this->assertContains($grandGrandChild, $period->getSocialIssues());
|
$this->assertContains($grandGrandChild, $period->getSocialIssues());
|
||||||
@ -63,7 +69,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T
|
|||||||
$period->addSocialIssue($issue);
|
$period->addSocialIssue($issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs());
|
$consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs($period, Step::PrePersist));
|
||||||
|
|
||||||
$this->assertCount(1, $period->getSocialIssues());
|
$this->assertCount(1, $period->getSocialIssues());
|
||||||
$this->assertSame($grandGrandChild, $period->getSocialIssues()->first());
|
$this->assertSame($grandGrandChild, $period->getSocialIssues()->first());
|
||||||
@ -81,7 +87,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T
|
|||||||
$entity = $this->generateClass($period, $socialIssues);
|
$entity = $this->generateClass($period, $socialIssues);
|
||||||
$consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener();
|
$consistency = new AccompanyingPeriodSocialIssueConsistencyEntityListener();
|
||||||
|
|
||||||
$consistency->preUpdate($entity, $this->generateLifecycleArgs());
|
$consistency->preUpdate($entity, $this->generateLifecycleArgs($period, Step::PreUpdate));
|
||||||
|
|
||||||
$this->assertCount(2, $period->getSocialIssues());
|
$this->assertCount(2, $period->getSocialIssues());
|
||||||
$this->assertContains($grandGrandChild, $period->getSocialIssues());
|
$this->assertContains($grandGrandChild, $period->getSocialIssues());
|
||||||
@ -106,7 +112,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T
|
|||||||
$period->addSocialIssue($issue);
|
$period->addSocialIssue($issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs());
|
$consistency->prePersistAccompanyingPeriod($period, $this->generateLifecycleArgs($period, Step::PrePersist));
|
||||||
|
|
||||||
$this->assertCount(1, $period->getSocialIssues());
|
$this->assertCount(1, $period->getSocialIssues());
|
||||||
$this->assertSame($grandGrandChild, $period->getSocialIssues()->first());
|
$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