Replaced swift mailer with symfony mailer
parent
f6c86285d9
commit
6a79aaeeaa
@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Mail\Transport;
|
||||
|
||||
use Swift_Events_EventListener;
|
||||
use Swift_Mime_SimpleMessage as SimpleMessage;
|
||||
use Swift_Transport as SwiftTransport;
|
||||
|
||||
abstract class Transport implements SwiftTransport
|
||||
{
|
||||
/**
|
||||
* Test if this Transport mechanism has started.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarted(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start this Transport mechanism.
|
||||
*/
|
||||
public function start()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop this Transport mechanism.
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this Transport mechanism is alive.
|
||||
*
|
||||
* If a Transport mechanism session is no longer functional, the method
|
||||
* returns FALSE. It is the responsibility of the developer to handle this
|
||||
* case and restart the Transport mechanism manually.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* if (!$transport->ping()) {
|
||||
* $transport->stop();
|
||||
* $transport->start();
|
||||
* }
|
||||
*
|
||||
* The Transport mechanism will be started, if it is not already.
|
||||
*
|
||||
* It is undefined if the Transport mechanism attempts to restart as long as
|
||||
* the return value reflects whether the mechanism is now functional.
|
||||
*
|
||||
* @return bool TRUE if the transport is alive
|
||||
*/
|
||||
public function ping(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin in the Transport.
|
||||
*
|
||||
* @param Swift_Events_EventListener $plugin
|
||||
*/
|
||||
public function registerPlugin(Swift_Events_EventListener $plugin)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unified list of all recipients
|
||||
*
|
||||
* @param SimpleMessage $message
|
||||
* @return array
|
||||
*/
|
||||
protected function allRecipients(SimpleMessage $message): array
|
||||
{
|
||||
return array_merge(
|
||||
(array)$message->getTo(),
|
||||
(array)$message->getCc(),
|
||||
(array)$message->getBcc()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a concatenated list of mail recipients
|
||||
*
|
||||
* @param SimpleMessage $message
|
||||
* @return string
|
||||
*/
|
||||
protected function getTo(SimpleMessage $message): string
|
||||
{
|
||||
return $this->formatTo($this->allRecipients($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $recipients
|
||||
* @return string
|
||||
*/
|
||||
protected function formatTo(array $recipients)
|
||||
{
|
||||
$list = [];
|
||||
foreach ($recipients as $address => $name) {
|
||||
$list[] = $name ? sprintf('%s <%s>', $name, $address) : $address;
|
||||
}
|
||||
|
||||
return implode(',', $list);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Mail\Transport\Stub;
|
||||
|
||||
use Engelsystem\Mail\Transport\Transport;
|
||||
use Swift_Mime_SimpleMessage as SimpleMessage;
|
||||
|
||||
class TransportImplementation extends Transport
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function send(SimpleMessage $message, &$failedRecipients = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SimpleMessage $message
|
||||
* @return array
|
||||
*/
|
||||
public function getAllRecipients(SimpleMessage $message)
|
||||
{
|
||||
return $this->allRecipients($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SimpleMessage $message
|
||||
* @return string
|
||||
*/
|
||||
public function getGetTo(SimpleMessage $message)
|
||||
{
|
||||
return $this->getTo($message);
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Mail\Transport;
|
||||
|
||||
use Engelsystem\Test\Unit\Mail\Transport\Stub\TransportImplementation;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Swift_Events_EventListener;
|
||||
use Swift_Mime_SimpleMessage as SimpleMessage;
|
||||
|
||||
class TransportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::isStarted
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::ping
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::registerPlugin
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::start
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::stop
|
||||
*/
|
||||
public function testMethods()
|
||||
{
|
||||
/** @var Swift_Events_EventListener|MockObject $plugin */
|
||||
$plugin = $this->getMockForAbstractClass(Swift_Events_EventListener::class);
|
||||
|
||||
$transport = new TransportImplementation();
|
||||
|
||||
$transport->start();
|
||||
$transport->registerPlugin($plugin);
|
||||
|
||||
$this->assertTrue($transport->isStarted());
|
||||
$this->assertTrue($transport->ping());
|
||||
|
||||
$transport->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @covers \Engelsystem\Mail\Transport\Transport::getTo
|
||||
*/
|
||||
public function testGetTo()
|
||||
{
|
||||
/** @var SimpleMessage|MockObject $message */
|
||||
$message = $this->createMock(SimpleMessage::class);
|
||||
/** @var TransportImplementation|MockObject $transport */
|
||||
$transport = $this->getMockBuilder(TransportImplementation::class)
|
||||
->onlyMethods(['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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue