summaryrefslogtreecommitdiff
path: root/tests/Unit/Mail/Transport/LogTransportTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:28:49 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:31:18 +0200
commit6187eed3bb08f200050a3078bd762b5731dfbe78 (patch)
tree06e0b08294c66449ed5f9f046a3bfe2097c7b4ad /tests/Unit/Mail/Transport/LogTransportTest.php
parentbc5764b33ffc8a92dfa1d788ba2a204dd991c3d9 (diff)
parentd36de2d26f5af76d5d4f34f8620694c6d0368983 (diff)
Merge remote-tracking branch 'MyIgel/mailing'
Diffstat (limited to 'tests/Unit/Mail/Transport/LogTransportTest.php')
-rw-r--r--tests/Unit/Mail/Transport/LogTransportTest.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/Unit/Mail/Transport/LogTransportTest.php b/tests/Unit/Mail/Transport/LogTransportTest.php
new file mode 100644
index 00000000..5eb3a667
--- /dev/null
+++ b/tests/Unit/Mail/Transport/LogTransportTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Mail\Transport;
+
+use Engelsystem\Mail\Transport\LogTransport;
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
+use Swift_Mime_SimpleMessage as SimpleMessage;
+
+class LogTransportTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Mail\Transport\LogTransport::__construct
+ * @covers \Engelsystem\Mail\Transport\LogTransport::send
+ */
+ public function testSend()
+ {
+ /** @var LoggerInterface|MockObject $logger */
+ $logger = $this->getMockForAbstractClass(LoggerInterface::class);
+ /** @var SimpleMessage|MockObject $message */
+ $message = $this->createMock(SimpleMessage::class);
+
+ $message->expects($this->once())
+ ->method('getSubject')
+ ->willReturn('Some subject');
+ $message->expects($this->once())
+ ->method('getHeaders')
+ ->willReturn('Head: er');
+ $message->expects($this->once())
+ ->method('toString')
+ ->willReturn('Message body');
+
+ $logger->expects($this->once())
+ ->method('debug')
+ ->willReturnCallback(function ($message, $context = []) {
+ foreach (array_keys($context) as $key) {
+ $this->assertContains(sprintf('{%s}', $key), $message);
+ }
+
+ $this->assertEquals('Some subject', $context['title']);
+ $this->assertEquals('foo@bar.batz,Lorem Ipsum <lor@em.ips>', $context['recipients']);
+ $this->assertContains('Head: er', $context['content']);
+ $this->assertContains('Message body', $context['content']);
+ });
+
+ /** @var LogTransport|MockObject $transport */
+ $transport = $this->getMockBuilder(LogTransport::class)
+ ->setConstructorArgs(['logger' => $logger])
+ ->setMethods(['allRecipients'])
+ ->getMock();
+ $transport->expects($this->exactly(2))
+ ->method('allRecipients')
+ ->with($message)
+ ->willReturn(['foo@bar.batz' => null, 'lor@em.ips' => 'Lorem Ipsum']);
+
+ $return = $transport->send($message);
+ $this->equalTo(2, $return);
+ }
+}