2018-09-05 13:40:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Mail;
|
|
|
|
|
|
|
|
use Engelsystem\Mail\Mailer;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-12-20 21:07:00 +01:00
|
|
|
use Symfony\Component\Mailer\Envelope;
|
|
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
|
|
use Symfony\Component\Mime\RawMessage;
|
2018-09-05 13:40:03 +02:00
|
|
|
|
|
|
|
class MailerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Mailer::__construct
|
|
|
|
* @covers \Engelsystem\Mail\Mailer::getFromAddress
|
|
|
|
* @covers \Engelsystem\Mail\Mailer::getFromName
|
2019-04-24 11:01:37 +02:00
|
|
|
* @covers \Engelsystem\Mail\Mailer::setFromAddress
|
2018-09-05 13:40:03 +02:00
|
|
|
* @covers \Engelsystem\Mail\Mailer::setFromName
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testInitAndSettersAndGetters(): void
|
2018-09-05 13:40:03 +02:00
|
|
|
{
|
2021-12-20 21:07:00 +01:00
|
|
|
/** @var MailerInterface|MockObject $symfonyMailer */
|
|
|
|
$symfonyMailer = $this->createMock(MailerInterface::class);
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
$mailer = new Mailer($symfonyMailer);
|
2018-09-05 13:40:03 +02:00
|
|
|
|
|
|
|
$mailer->setFromName('From Name');
|
|
|
|
$this->assertEquals('From Name', $mailer->getFromName());
|
|
|
|
|
|
|
|
$mailer->setFromAddress('from@foo.bar');
|
|
|
|
$this->assertEquals('from@foo.bar', $mailer->getFromAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\Mailer::send
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testSend(): void
|
2018-09-05 13:40:03 +02:00
|
|
|
{
|
2021-12-20 21:07:00 +01:00
|
|
|
/** @var MailerInterface|MockObject $symfonyMailer */
|
|
|
|
$symfonyMailer = $this->createMock(MailerInterface::class);
|
|
|
|
$symfonyMailer->expects($this->once())
|
2018-09-05 13:40:03 +02:00
|
|
|
->method('send')
|
2022-12-14 19:15:20 +01:00
|
|
|
->willReturnCallback(function (RawMessage $message, Envelope $envelope = null): void {
|
2021-12-20 21:07:00 +01:00
|
|
|
$this->assertStringContainsString('to@xam.pel', $message->toString());
|
|
|
|
$this->assertStringContainsString('foo@bar.baz', $message->toString());
|
|
|
|
$this->assertStringContainsString('Test Tester', $message->toString());
|
|
|
|
$this->assertStringContainsString('Foo Bar', $message->toString());
|
|
|
|
$this->assertStringContainsString('Lorem Ipsum!', $message->toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
$mailer = new Mailer($symfonyMailer);
|
2018-09-05 13:40:03 +02:00
|
|
|
$mailer->setFromAddress('foo@bar.baz');
|
2021-12-20 21:07:00 +01:00
|
|
|
$mailer->setFromName('Test Tester');
|
2018-09-05 13:40:03 +02:00
|
|
|
|
2021-12-20 21:07:00 +01:00
|
|
|
$mailer->send('to@xam.pel', 'Foo Bar', 'Lorem Ipsum!');
|
2018-09-05 13:40:03 +02:00
|
|
|
}
|
|
|
|
}
|