2018-09-05 13:40:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Mail\Transport;
|
|
|
|
|
|
|
|
use Engelsystem\Test\Unit\Mail\Transport\Stub\TransportImplementation;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-04-24 12:58:13 +02:00
|
|
|
use Swift_Events_EventListener;
|
2018-09-05 13:40:03 +02:00
|
|
|
use Swift_Mime_SimpleMessage as SimpleMessage;
|
|
|
|
|
|
|
|
class TransportTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::isStarted
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::ping
|
2019-04-24 12:58:13 +02:00
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::registerPlugin
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::start
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::stop
|
2018-09-05 13:40:03 +02:00
|
|
|
*/
|
|
|
|
public function testMethods()
|
|
|
|
{
|
2019-04-24 12:58:13 +02:00
|
|
|
/** @var Swift_Events_EventListener|MockObject $plugin */
|
|
|
|
$plugin = $this->getMockForAbstractClass(Swift_Events_EventListener::class);
|
|
|
|
|
2018-09-05 13:40:03 +02:00
|
|
|
$transport = new TransportImplementation();
|
|
|
|
|
2019-04-24 12:58:13 +02:00
|
|
|
$transport->start();
|
|
|
|
$transport->registerPlugin($plugin);
|
|
|
|
|
2018-09-05 13:40:03 +02:00
|
|
|
$this->assertTrue($transport->isStarted());
|
|
|
|
$this->assertTrue($transport->ping());
|
2019-04-24 12:58:13 +02:00
|
|
|
|
|
|
|
$transport->stop();
|
2018-09-05 13:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::allRecipients
|
|
|
|
*/
|
|
|
|
public function testAllRecipients()
|
|
|
|
{
|
|
|
|
/** @var SimpleMessage|MockObject $message */
|
|
|
|
$message = $this->createMock(SimpleMessage::class);
|
|
|
|
$transport = new TransportImplementation();
|
|
|
|
$message->expects($this->once())
|
|
|
|
->method('getTo')
|
|
|
|
->willReturn([
|
|
|
|
'foo@bar.batz' => 'Foo Bar',
|
|
|
|
'lorem@ipsum.dolor' => null,
|
|
|
|
]);
|
|
|
|
$message->expects($this->once())
|
|
|
|
->method('getCc')
|
|
|
|
->willReturn([
|
|
|
|
'to@bar.batz' => null,
|
|
|
|
]);
|
|
|
|
$message->expects($this->once())
|
|
|
|
->method('getBcc')
|
|
|
|
->willReturn([
|
|
|
|
'secret@bar.batz' => 'I\'m secret!',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'foo@bar.batz' => 'Foo Bar',
|
|
|
|
'lorem@ipsum.dolor' => null,
|
|
|
|
'to@bar.batz' => null,
|
|
|
|
'secret@bar.batz' => 'I\'m secret!',
|
|
|
|
],
|
|
|
|
$transport->getAllRecipients($message)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::formatTo
|
2019-04-24 11:01:37 +02:00
|
|
|
* @covers \Engelsystem\Mail\Transport\Transport::getTo
|
2018-09-05 13:40:03 +02:00
|
|
|
*/
|
|
|
|
public function testGetTo()
|
|
|
|
{
|
|
|
|
/** @var SimpleMessage|MockObject $message */
|
|
|
|
$message = $this->createMock(SimpleMessage::class);
|
|
|
|
/** @var TransportImplementation|MockObject $transport */
|
|
|
|
$transport = $this->getMockBuilder(TransportImplementation::class)
|
|
|
|
->setMethods(['allRecipients'])
|
|
|
|
->getMock();
|
|
|
|
$transport->expects($this->once())
|
|
|
|
->method('allRecipients')
|
|
|
|
->with($message)
|
|
|
|
->willReturn([
|
|
|
|
'foo@bar.batz' => null,
|
|
|
|
'lorem@ipsum.dolor' => 'Developer',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$return = $transport->getGetTo($message);
|
|
|
|
$this->assertEquals('foo@bar.batz,Developer <lorem@ipsum.dolor>', $return);
|
|
|
|
}
|
|
|
|
}
|