public function testShouldRenderTwigParts() { $twig = $this->prophesize(\Twig_Environment::class); $twig->render('template.twig.html', [])->shouldBeCalled(); $processor = new TwigProcessor($twig->reveal()); $email = new Email(); $email->addTo('*****@*****.**')->addPart(Email\TwigTemplatePart::create('template.twig.html'), 'text/html'); $processor->onPreNotify(new PreNotifyEvent($email)); }
public function testShouldAddRecipientVariables() { $that = $this; $this->mailgun->sendMessage('www.example.org', Argument::type('array'), Argument::cetera())->shouldBeCalled()->will(function ($args) use($that) { $postData = $args[1]; $that->assertArrayHasKey('recipient-variables', $postData); $that->assertJson($postData['recipient-variables']); $resp = new \stdClass(); $resp->http_response_code = 200; return $resp; }); $this->handler->notify(Email::create()->addVariablesForRecipient('*****@*****.**', ['key' => 'value'])->addTo('*****@*****.**')); }
public function testShouldSkipNotSupportedHandlers() { $notification = Email::create(); $handler = $this->prophesize(NotificationHandlerInterface::class); $handler->getName()->willReturn('swiftmailer'); $handler->supports(Argument::any())->willReturn(false); $handler->notify(Argument::any())->shouldNotBeCalled(); $handler2 = $this->prophesize(NotificationHandlerInterface::class); $handler2->getName()->willReturn('default'); $handler2->supports(Argument::any())->willReturn(true); $handler2->notify(Argument::any())->shouldBeCalled(); $this->manager->addHandler($handler->reveal()); $this->manager->addHandler($handler2->reveal()); $this->manager->notify($notification); }
/** * Adds the {@see Email::additionalHeaders} to the message. * * @param Email $notification * @param \Swift_Message $email */ protected function addHeaders(Email $notification, \Swift_Message $email) { $headers = $email->getHeaders(); foreach ($notification->getAdditionalHeaders() as $key => $value) { if ($value instanceof \DateTime) { $headers->addDateHeader($key, $value); } else { $headers->addTextHeader($key, $value); } } }
public function testShouldSetMultipartAlternativeIfEmailIsMultipart() { $email = new Email(); $email->addPart(Email\Part::create('BODY PART', 'text/plain'))->addPart(Email\Part::create('PART 2', 'text/html')); $this->mailer->send(Argument::that(function ($argument) { if (!$argument instanceof \Swift_Message) { return false; } $this->assertCount(2, $argument->getChildren()); $this->assertEquals('multipart/alternative', $argument->getContentType()); return true; }))->willReturn(1); $this->handler->notify($email); }
/** * @expectedException \Fazland\Notifire\Exception\PartContentTypeMismatchException */ public function testAddPartShouldThrowIfTwoPartsWithSameContentTypeHasAdded() { Email::create()->addPart(Email\Part::create('BlaBla', 'text/html'))->addPart(Email\Part::create('Foo bar', 'text/html')); }