From 01e9c22695a3e495f07ab445750221af72e09fe4 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 5 Sep 2018 13:40:03 +0200 Subject: Implemented mailing abstraction Closes #434 --- tests/Unit/Mail/MailerTest.php | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/Unit/Mail/MailerTest.php (limited to 'tests/Unit/Mail/MailerTest.php') diff --git a/tests/Unit/Mail/MailerTest.php b/tests/Unit/Mail/MailerTest.php new file mode 100644 index 00000000..24c6f69a --- /dev/null +++ b/tests/Unit/Mail/MailerTest.php @@ -0,0 +1,77 @@ +createMock(SwiftMailer::class); + + $mailer = new Mailer($swiftMailer); + + $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 + */ + 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('Foo Bar') + ->willReturn($message); + + $message->expects($this->once()) + ->method('setBody') + ->with('Lorem Ipsum!') + ->willReturn($message); + + $mailer = new Mailer($swiftMailer); + $mailer->setFromAddress('foo@bar.baz'); + $mailer->setFromName('Lorem Ipsum'); + + $return = $mailer->send('to@xam.pel', 'Foo Bar', 'Lorem Ipsum!'); + $this->equalTo(1, $return); + } +} -- cgit v1.2.3-54-g00ecf