mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add test to NotificationMailer::postPersistComment
This commit is contained in:
parent
2cec4a770e
commit
65b585d4a9
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Notification\Email;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Notification;
|
||||||
|
use Chill\MainBundle\Entity\NotificationComment;
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
|
class NotificationMailerTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function testPostPersistComment(): void
|
||||||
|
{
|
||||||
|
$this->expectNotToPerformAssertions();
|
||||||
|
$user1 = (new User())->setEmail('user1@foo.com');
|
||||||
|
$user2 = (new User())->setEmail('user2@foo.com');
|
||||||
|
$user3 = (new User())->setEmail('user3@foo.com');
|
||||||
|
|
||||||
|
$notification = new Notification();
|
||||||
|
$notification
|
||||||
|
->setTitle('test notification')
|
||||||
|
->setSender($user1)
|
||||||
|
->addAddressee($user2)
|
||||||
|
->addAddressee($user3)
|
||||||
|
;
|
||||||
|
|
||||||
|
$comment = (new NotificationComment())
|
||||||
|
->setContent("foo bar baz")
|
||||||
|
->setCreatedBy($user2)
|
||||||
|
;
|
||||||
|
$notification->addComment($comment);
|
||||||
|
|
||||||
|
$mailer = $this->prophesize(MailerInterface::class);
|
||||||
|
|
||||||
|
// a mail only to user1 and user3 should have been sent
|
||||||
|
$mailer->send(Argument::that(function (Email $email) {
|
||||||
|
foreach ($email->getTo() as $address) {
|
||||||
|
if ($address->getAddress() === 'user1@foo.com' || $address->getAddress() === 'user3@foo.com') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
|
||||||
|
$objectManager = $this->prophesize(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
$mailer = $this->buildNotificationMailer($mailer->reveal());
|
||||||
|
$mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildNotificationMailer(
|
||||||
|
MailerInterface $mailer = null,
|
||||||
|
): NotificationMailer
|
||||||
|
{
|
||||||
|
return new NotificationMailer(
|
||||||
|
$mailer,
|
||||||
|
new NullLogger(),
|
||||||
|
new Translator('fr')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user