summaryrefslogtreecommitdiff
path: root/tests/Unit
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-05 15:35:14 +0200
committermsquare <msquare@notrademark.de>2018-10-30 22:50:22 +0100
commit90e1a949623ead173c0952f802d7b5c5487251b1 (patch)
tree544d29dde573cb135b514d0a84c2d95e9207392c /tests/Unit
parent0aa5f079258afd5276917c1aff565ec1c6411821 (diff)
Make application name configurable
* Added app_name configuration option * Extended `EngelsystemMailer` to prepend the application name to all mails Closes #426
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Mail/EngelsystemMailerTest.php50
-rw-r--r--tests/Unit/Mail/MailerServiceProviderTest.php4
2 files changed, 53 insertions, 1 deletions
diff --git a/tests/Unit/Mail/EngelsystemMailerTest.php b/tests/Unit/Mail/EngelsystemMailerTest.php
index aae6e267..0f60ff3b 100644
--- a/tests/Unit/Mail/EngelsystemMailerTest.php
+++ b/tests/Unit/Mail/EngelsystemMailerTest.php
@@ -7,6 +7,7 @@ use Engelsystem\Renderer\Renderer;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Swift_Mailer as SwiftMailer;
+use Swift_Message as SwiftMessage;
class EngelsystemMailerTest extends TestCase
{
@@ -37,4 +38,53 @@ class EngelsystemMailerTest extends TestCase
$return = $mailer->sendView('foo@bar.baz', 'Lorem dolor', 'test/template.tpl', ['dev' => true]);
$this->equalTo(1, $return);
}
+
+ /**
+ * @covers \Engelsystem\Mail\EngelsystemMailer::send
+ * @covers \Engelsystem\Mail\EngelsystemMailer::setSubjectPrefix
+ * @covers \Engelsystem\Mail\EngelsystemMailer::getSubjectPrefix
+ */
+ public function testSend()
+ {
+ /** @var SwiftMessage|MockObject $message */
+ $message = $this->createMock(SwiftMessage::class);
+ /** @var SwiftMailer|MockObject $swiftMailer */
+ $swiftMailer = $this->createMock(SwiftMailer::class);
+ $swiftMailer->expects($this->once())
+ ->method('createMessage')
+ ->willReturn($message);
+ $swiftMailer->expects($this->once())
+ ->method('send')
+ ->willReturn(1);
+
+ $message->expects($this->once())
+ ->method('setTo')
+ ->with(['to@xam.pel'])
+ ->willReturn($message);
+
+ $message->expects($this->once())
+ ->method('setFrom')
+ ->with('foo@bar.baz', 'Lorem Ipsum')
+ ->willReturn($message);
+
+ $message->expects($this->once())
+ ->method('setSubject')
+ ->with('[Mail test] Foo Bar')
+ ->willReturn($message);
+
+ $message->expects($this->once())
+ ->method('setBody')
+ ->with('Lorem Ipsum!')
+ ->willReturn($message);
+
+ $mailer = new EngelsystemMailer($swiftMailer);
+ $mailer->setFromAddress('foo@bar.baz');
+ $mailer->setFromName('Lorem Ipsum');
+ $mailer->setSubjectPrefix('Mail test');
+
+ $this->assertEquals('Mail test', $mailer->getSubjectPrefix());
+
+ $return = $mailer->send('to@xam.pel', 'Foo Bar', 'Lorem Ipsum!');
+ $this->equalTo(1, $return);
+ }
}
diff --git a/tests/Unit/Mail/MailerServiceProviderTest.php b/tests/Unit/Mail/MailerServiceProviderTest.php
index 0c841e9e..793cd1f2 100644
--- a/tests/Unit/Mail/MailerServiceProviderTest.php
+++ b/tests/Unit/Mail/MailerServiceProviderTest.php
@@ -20,7 +20,8 @@ class MailerServiceProviderTest extends ServiceProviderTest
{
/** @var array */
protected $defaultConfig = [
- 'email' => [
+ 'app_name' => 'Engelsystem App',
+ 'email' => [
'driver' => 'mail',
'from' => [
'name' => 'Engelsystem',
@@ -58,6 +59,7 @@ class MailerServiceProviderTest extends ServiceProviderTest
/** @var EngelsystemMailer $mailer */
$mailer = $app->get('mailer');
+ $this->assertEquals('Engelsystem App', $mailer->getSubjectPrefix());
$this->assertEquals('Engelsystem', $mailer->getFromName());
$this->assertEquals('foo@bar.batz', $mailer->getFromAddress());