2018-09-05 13:40:03 +02:00
|
|
|
<?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('toString')
|
2019-10-27 12:32:28 +01:00
|
|
|
->willReturn("Head: er\n\nMessage body");
|
2018-09-05 13:40:03 +02:00
|
|
|
|
|
|
|
$logger->expects($this->once())
|
|
|
|
->method('debug')
|
|
|
|
->willReturnCallback(function ($message, $context = []) {
|
|
|
|
foreach (array_keys($context) as $key) {
|
2019-04-24 10:45:00 +02:00
|
|
|
$this->assertStringContainsString(sprintf('{%s}', $key), $message);
|
2018-09-05 13:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals('Some subject', $context['title']);
|
|
|
|
$this->assertEquals('foo@bar.batz,Lorem Ipsum <lor@em.ips>', $context['recipients']);
|
2019-04-24 10:45:00 +02:00
|
|
|
$this->assertStringContainsString('Head: er', $context['content']);
|
|
|
|
$this->assertStringContainsString('Message body', $context['content']);
|
2018-09-05 13:40:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/** @var LogTransport|MockObject $transport */
|
|
|
|
$transport = $this->getMockBuilder(LogTransport::class)
|
|
|
|
->setConstructorArgs(['logger' => $logger])
|
2019-11-06 12:29:58 +01:00
|
|
|
->onlyMethods(['allRecipients'])
|
2018-09-05 13:40:03 +02:00
|
|
|
->getMock();
|
|
|
|
$transport->expects($this->exactly(2))
|
|
|
|
->method('allRecipients')
|
|
|
|
->with($message)
|
|
|
|
->willReturn(['foo@bar.batz' => null, 'lor@em.ips' => 'Lorem Ipsum']);
|
|
|
|
|
|
|
|
$return = $transport->send($message);
|
2020-04-19 23:14:06 +02:00
|
|
|
$this->assertEquals(2, $return);
|
2018-09-05 13:40:03 +02:00
|
|
|
}
|
|
|
|
}
|