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;
|
2021-12-20 21:07:00 +01:00
|
|
|
use Psr\Log\Test\TestLogger;
|
|
|
|
use Symfony\Component\Mime\Email;
|
2018-09-05 13:40:03 +02:00
|
|
|
|
|
|
|
class LogTransportTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Transport\LogTransport::__construct
|
2021-12-20 21:07:00 +01:00
|
|
|
* @covers \Engelsystem\Mail\Transport\LogTransport::doSend
|
2018-09-05 13:40:03 +02:00
|
|
|
*/
|
|
|
|
public function testSend()
|
|
|
|
{
|
2021-12-20 21:07:00 +01:00
|
|
|
$logger = new TestLogger();
|
|
|
|
$email = (new Email())
|
|
|
|
->from('some@email.host')
|
|
|
|
->to('foo@bar.baz', 'Test Tester <test@example.local>')
|
|
|
|
->subject('Testing')
|
|
|
|
->text('Message body');
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
$transport = new LogTransport($logger);
|
|
|
|
$transport->send($email);
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
$this->assertTrue($logger->hasDebugThatContains('Send mail to'));
|
|
|
|
}
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Transport\LogTransport::__toString
|
|
|
|
*/
|
|
|
|
public function testToString()
|
|
|
|
{
|
|
|
|
/** @var LoggerInterface|MockObject $logger */
|
|
|
|
$logger = $this->getMockForAbstractClass(LoggerInterface::class);
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
$transport = new LogTransport($logger);
|
|
|
|
$this->assertEquals('log://', (string)$transport);
|
2018-09-05 13:40:03 +02:00
|
|
|
}
|
|
|
|
}
|