deferring the sending of notification to kernel.terminate: prepare

This commit is contained in:
2022-04-22 11:34:41 +02:00
parent e246ccbcd9
commit 33f93d484d
6 changed files with 137 additions and 13 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace Notification\EventListener;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Notification\EventListener\PersistNotificationOnTerminateEventSubscriber;
use Chill\MainBundle\Notification\NotificationPersister;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
class PersistNotificationOnTerminateEventSubscriberTest extends TestCase
{
use ProphecyTrait;
public function testNotificationIsPersisted()
{
$persister = new NotificationPersister();
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->shouldBeCalledTimes(1);
$em->flush()->shouldBeCalledTimes(1);
$event = $this->prophesize(TerminateEvent::class);
$event->isMasterRequest()->willReturn(true);
$eventSubscriber = new PersistNotificationOnTerminateEventSubscriber($em->reveal(), $persister);
$notification = new Notification();
$persister->persist($notification);
$eventSubscriber->onKernelTerminate($event->reveal());
}
}