From 0ffc38e47eff3ff606234b58df368fb1ccb4b653 Mon Sep 17 00:00:00 2001 From: Sascha Date: Mon, 11 Jun 2018 10:46:31 +0200 Subject: [PATCH 1/6] reduced mail-package --- src/Address/Address.php | 6 - src/Address/AddressContainer.php | 6 - src/Assistant/Assistant.php | 164 ------------------------- src/Attachment/AttachmentContainer.php | 6 - src/Attachment/AttachmentInterface.php | 6 - src/Container/AbstractContainer.php | 11 +- src/Content.php | 6 - src/Mail.php | 73 ++++++----- src/Mailer/MailerInterface.php | 30 ----- src/Pipeline/MailPipeInterface.php | 20 --- src/Pipeline/MailPipeline.php | 42 ------- src/Pipeline/MailPipelineInterface.php | 19 --- src/Pipeline/Pipe/CustomPipe.php | 36 ------ src/Pipeline/Pipe/MailerPipe.php | 52 -------- src/Pipeline/ProcessResult.php | 145 ---------------------- tests/Address/AddressContainerTest.php | 6 - tests/Assistant/AssistantTest.php | 63 ---------- tests/ContentTest.php | 7 -- tests/MailTest.php | 31 ++--- tests/Pipeline/MailPipelineTest.php | 65 ---------- tests/Pipeline/Pipe/CustomPipeTest.php | 26 ---- tests/Pipeline/Pipe/MailerPipeTest.php | 70 ----------- tests/Pipeline/ProcessResultTest.php | 77 ------------ 23 files changed, 50 insertions(+), 917 deletions(-) delete mode 100644 src/Assistant/Assistant.php delete mode 100644 src/Mailer/MailerInterface.php delete mode 100644 src/Pipeline/MailPipeInterface.php delete mode 100644 src/Pipeline/MailPipeline.php delete mode 100644 src/Pipeline/MailPipelineInterface.php delete mode 100644 src/Pipeline/Pipe/CustomPipe.php delete mode 100644 src/Pipeline/Pipe/MailerPipe.php delete mode 100644 src/Pipeline/ProcessResult.php delete mode 100644 tests/Assistant/AssistantTest.php delete mode 100644 tests/Pipeline/MailPipelineTest.php delete mode 100644 tests/Pipeline/Pipe/CustomPipeTest.php delete mode 100644 tests/Pipeline/Pipe/MailerPipeTest.php delete mode 100644 tests/Pipeline/ProcessResultTest.php diff --git a/src/Address/Address.php b/src/Address/Address.php index 4e2e5b1..b6dab64 100644 --- a/src/Address/Address.php +++ b/src/Address/Address.php @@ -1,10 +1,4 @@ from($sender); - - return $assistant; - } - - /** - * Assistant constructor. - */ - public function __construct() - { - $this->mail = new Mail(); - } - - /** - * @param Address $sender - * - * @return Assistant - */ - public function from(Address $sender): self - { - $this->mail->setSender($sender); - - return $this; - } - - /** - * @param Address $to - * - * @return Assistant - */ - public function to(Address $to): self - { - $this->mail->recipients()->addAddress($to); - - return $this; - } - - /** - * @param string $content - * - * @return Assistant - */ - public function write(string $content): self - { - $this->mail->content()->setText($content); - - return $this; - } - - /** - * @param string $html - * - * @return Assistant - */ - public function writeHtml(string $html): self - { - $this->mail->content()->setHtml($html); - - return $this; - } - - /** - * @param Address $address - * - * @return Assistant - */ - public function copyTo(Address $address): self - { - $this->mail->ccs()->addAddress($address); - - return $this; - } - - /** - * @param Address $address - * - * @return Assistant - */ - public function blindTo(Address $address): self - { - $this->mail->bccs()->addAddress($address); - - return $this; - } - - /** - * @param string $subject - * - * @return Assistant - */ - public function withSubject(string $subject): self - { - $this->mail->setSubject($subject); - - return $this; - } - - /** - * @param AttachmentInterface $attachment - * - * @return Assistant - */ - public function withAttachment(AttachmentInterface $attachment): self - { - $this->mail->attachments()->addAttachment($attachment); - - return $this; - } - - /** - * @return Mail - */ - public function getMail(): Mail - { - return $this->mail; - } - - /** - * @param MailPipelineInterface $pipeline - * - * @return ProcessResult - */ - public function sendThrough(MailPipelineInterface $pipeline): ProcessResult - { - return $pipeline->process($this->getMail()); - } -} \ No newline at end of file diff --git a/src/Attachment/AttachmentContainer.php b/src/Attachment/AttachmentContainer.php index 15b25d9..dec0643 100644 --- a/src/Attachment/AttachmentContainer.php +++ b/src/Attachment/AttachmentContainer.php @@ -1,10 +1,4 @@ content = new Content(); $this->recipients = new AddressContainer(); @@ -77,7 +71,6 @@ public function __construct(DateTime $createdAt = null) $this->bccs = new AddressContainer(); $this->replyTos = new AddressContainer(); $this->attachments = new AttachmentContainer(); - $this->createdAt = $createdAt !== null ? $createdAt : new DateTime(); } /** @@ -88,13 +81,35 @@ public function setSender(Address $sender) $this->sender = $sender; } + /** + * @param Address $from + * + */ + public function setFrom(Address $from) + { + $this->from = $from; + } + + /** + * @return Address + * @throws Exception + */ + public function getFrom(): Address + { + if (!$this->hasFrom()) { + throw new Exception('There is no from given'); + } + + return $this->from; + } + /** * @return Address * @throws Exception */ public function sender(): Address { - if (!$this->isSenderSet()) { + if (!$this->hasSender()) { throw new Exception('There is no sender given'); } @@ -104,11 +119,19 @@ public function sender(): Address /** * @return bool */ - public function isSenderSet(): bool + public function hasSender(): bool { return $this->sender !== null; } + /** + * @return bool + */ + public function hasFrom(): bool + { + return $this->from !== null; + } + /** * @return Content */ @@ -149,30 +172,6 @@ public function attachments(): AttachmentContainer return $this->attachments; } - /** - * @return string - */ - public function getId(): string - { - return $this->id; - } - - /** - * @param string $id - */ - public function setId(string $id) - { - $this->id = $id; - } - - /** - * @return DateTime - */ - public function getCreatedAt(): DateTime - { - return $this->createdAt; - } - /** * @return string */ diff --git a/src/Mailer/MailerInterface.php b/src/Mailer/MailerInterface.php deleted file mode 100644 index 737ebbf..0000000 --- a/src/Mailer/MailerInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -pipes[] = $mailpipe; - } - - /** - * @param Mail $mail - * - * @return ProcessResult - */ - public function process(Mail $mail): ProcessResult - { - $processMail = clone $mail; - $result = ProcessResult::new(); - $result->setStatus(ProcessResult::SUCCEEDED); - foreach ($this->pipes as $pipe) { - $result = $pipe->process($processMail, $result); - } - - return $result; - } -} \ No newline at end of file diff --git a/src/Pipeline/MailPipelineInterface.php b/src/Pipeline/MailPipelineInterface.php deleted file mode 100644 index a9a39f2..0000000 --- a/src/Pipeline/MailPipelineInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -callable = $callable; - } - - /** - * @param Mail $mail - * @param ProcessResult $result - * - * @return ProcessResult - */ - public function process(Mail $mail, ProcessResult $result): ProcessResult - { - return call_user_func($this->callable, $mail, $result); - } -} \ No newline at end of file diff --git a/src/Pipeline/Pipe/MailerPipe.php b/src/Pipeline/Pipe/MailerPipe.php deleted file mode 100644 index a2083f8..0000000 --- a/src/Pipeline/Pipe/MailerPipe.php +++ /dev/null @@ -1,52 +0,0 @@ -mailer = $mailer; - } - - /** - * @param Mail $mail - * @param ProcessResult $result - * - * @return ProcessResult - */ - public function process(Mail $mail, ProcessResult $result): ProcessResult - { - if ($result->errored()) { - return $result; - } - - if ($this->mailer->send($mail)) { - $result->setStatus(ProcessResult::SUCCEEDED); - } else { - $result->setStatus(ProcessResult::FAILED); - $result->addInfo(self::class, $this->mailer->getErrorInfo()); - } - - return $result; - } -} \ No newline at end of file diff --git a/src/Pipeline/ProcessResult.php b/src/Pipeline/ProcessResult.php deleted file mode 100644 index a92cac6..0000000 --- a/src/Pipeline/ProcessResult.php +++ /dev/null @@ -1,145 +0,0 @@ -status = $status; - - return $this; - } - - /** - * @return bool - */ - public function succeeded(): bool - { - return $this->status === self::SUCCEEDED; - } - - /** - * @return bool - */ - public function failed(): bool - { - return $this->status === self::FAILED; - } - - /** - * @return bool - */ - public function errored(): bool - { - return $this->status === self::ERRORED; - } - - /** - * @param string $key - * @param string $info - */ - public function addInfo(string $key, string $info) - { - $this->infos[$key] = $info; - } - - /** - * @param string $key - * - * @return bool - */ - public function hasInfoFor(string $key): bool - { - return array_key_exists($key, $this->infos); - } - - /** - * @param string $key - * - * @return string - * @throws Exception - */ - public function getInfo(string $key): string - { - if ($this->hasInfoFor($key)) { - return $this->infos[$key]; - } - throw new Exception(sprintf('no information available for %s', $key)); - } - - /** - * @param $key - * - * @return bool - */ - public function hasAttribute($key): bool - { - return array_key_exists($key, $this->attributes); - } - - /** - * @param $key - * - * @return mixed - * @throws Exception - */ - public function getAttribute($key) - { - if ($this->hasAttribute($key)) { - return $this->attributes[$key]; - } - throw new Exception(sprintf('no attribute set fpr %s', $key)); - } - - /** - * @param $key - * @param $value - * - * @return self - */ - public function withAttribute($key, $value): self - { - $this->attributes[$key] = $value; - - return $this; - } -} \ No newline at end of file diff --git a/tests/Address/AddressContainerTest.php b/tests/Address/AddressContainerTest.php index 146b634..98d34d6 100644 --- a/tests/Address/AddressContainerTest.php +++ b/tests/Address/AddressContainerTest.php @@ -1,10 +1,4 @@ assertInstanceOf(Assistant::class, Assistant::listen()); - } - - public function testListenTo() - { - $this->assertEquals('test@test.de', Assistant::listenTo(new Address('test@test.de')) - ->getMail()->sender()->getAddress()); - } - - public function testWrite() - { - $this->assertEquals('This is a test', Assistant::listen()->write('This is a test')->getMail()->content()->getText()); - } - - public function testWritehHtml() - { - $this->assertEquals('This is a test', Assistant::listen() - ->writeHtml('This is a test')->getMail()->content()->getHtml()); - } - - public function testCopyTo() - { - $first = new Address('copy1@test.de'); - $second = new Address('copy2@test.de'); - $this->assertEquals([$first, $second], Assistant::listen()->copyTo($first)->copyTo($second)->getMail()->ccs()->asArray()); - } - - public function testBlindTo() - { - $first = new Address('blind1@test.de'); - $second = new Address('blind2@test.de'); - $this->assertEquals([$first, $second], Assistant::listen()->blindTo($first)->blindTo($second)->getMail()->bccs()->asArray()); - } - - public function testWithSubject() - { - $this->assertEquals('This is the Subject', Assistant::listen() - ->withSubject('This is the Subject')->getMail()->getSubject()); - } - - public function testSendThrough() - { - $this->assertInstanceOf(ProcessResult::class, Assistant::listen()->sendThrough(new MailPipeline())); - } -} \ No newline at end of file diff --git a/tests/ContentTest.php b/tests/ContentTest.php index a745f17..bccd802 100644 --- a/tests/ContentTest.php +++ b/tests/ContentTest.php @@ -1,12 +1,5 @@ setId('kJhdhw7271Daw'); - $this->assertEquals('kJhdhw7271Daw', $mail->getId()); - - $mail = new Mail(); - $mail->setId('klj90823KHJDHW'); - $this->assertEquals('klj90823KHJDHW', $mail->getId()); - - $mail = new Mail(); - $this->assertEquals('', $mail->getId()); - } - public function testGetSubject() { $mail = new Mail(); @@ -47,15 +33,22 @@ public function testGetSubject() public function testGetSender() { $mail = new Mail(); - $this->assertFalse($mail->isSenderSet()); + $this->assertFalse($mail->hasSender()); $mail->setSender(new Address('john.doe@test.de', 'John Doe')); $this->assertTrue($mail->sender()->equals(new Address('john.doe@test.de', 'John Doe'))); - $this->assertTrue($mail->isSenderSet()); + $this->assertTrue($mail->hasSender()); $mail->setSender(new Address('max.mustermann@test.de', 'Max Mustermann')); $this->assertTrue($mail->sender()->equals(new Address('max.mustermann@test.de'))); } + public function testGetFrom() + { + $mail = new Mail(); + $mail->setFrom(new Address('john.doe@test.de', 'John Doe')); + $this->assertTrue($mail->getFrom()->equals(new Address('john.doe@test.de', 'John Doe'))); + } + /** * @return Mail */ @@ -88,10 +81,4 @@ public function testAttachments() { $this->assertInstanceOf(AttachmentContainer::class, $this->getMail()->attachments()); } - - public function testGetCreatedAt() - { - $mail = new Mail(new DateTime('2016-01-01')); - $this->assertEquals(new DateTime('2016-01-01'), $mail->getCreatedAt()); - } } \ No newline at end of file diff --git a/tests/Pipeline/MailPipelineTest.php b/tests/Pipeline/MailPipelineTest.php deleted file mode 100644 index 1933edd..0000000 --- a/tests/Pipeline/MailPipelineTest.php +++ /dev/null @@ -1,65 +0,0 @@ -specify('No pipe given', function () { - $pipeline = new MailPipeline(); - $mail = new Mail(); - $this->assertTrue($pipeline->process($mail)->succeeded()); - }); - - $this->specify('Append single Pipe', function () { - $pipeline = new MailPipeline(); - $mail = new Mail(); - $pipeline->appendPipe(new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->setStatus(ProcessResult::ERRORED); - })); - $result = $pipeline->process($mail); - $this->assertTrue($result->errored()); - }); - - $this->specify('Append multiple Pipes', function () { - $pipeline = new MailPipeline(); - $mail = new Mail(); - $pipeline->appendPipe(new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->setStatus(ProcessResult::ERRORED); - })); - $pipeline->appendPipe(new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->setStatus(ProcessResult::FAILED); - })); - $result = $pipeline->process($mail); - $this->assertTrue($result->failed()); - }); - - $this->specify('Append multiple Pipes, passing Attributes', function () { - $pipeline = new MailPipeline(); - $mail = new Mail(); - $pipeline->appendPipe(new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->withAttribute('test1', 'test1'); - })); - $pipeline->appendPipe(new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->withAttribute('test2', 'test2'); - })); - $result = $pipeline->process($mail); - $this->assertTrue($result->hasAttribute('test1')); - $this->assertTrue($result->hasAttribute('test2')); - }); - } -} \ No newline at end of file diff --git a/tests/Pipeline/Pipe/CustomPipeTest.php b/tests/Pipeline/Pipe/CustomPipeTest.php deleted file mode 100644 index 1dfafca..0000000 --- a/tests/Pipeline/Pipe/CustomPipeTest.php +++ /dev/null @@ -1,26 +0,0 @@ -assertFalse($result->failed()); - $pipe = new CustomPipe(function (Mail $mail, ProcessResult $result) { - return $result->setStatus(ProcessResult::FAILED); - }); - $this->assertTrue($pipe->process($mail, $result)->failed()); - } -} \ No newline at end of file diff --git a/tests/Pipeline/Pipe/MailerPipeTest.php b/tests/Pipeline/Pipe/MailerPipeTest.php deleted file mode 100644 index e07d134..0000000 --- a/tests/Pipeline/Pipe/MailerPipeTest.php +++ /dev/null @@ -1,70 +0,0 @@ -specify('successfully send', function () { - $pipe = new MailerPipe($this->getMailerMock(true)); - $result = ProcessResult::new(); - $mail = new Mail(); - $this->assertTrue($pipe->process($mail, $result)->succeeded()); - }); - - $this->specify('send failed', function () { - $pipe = new MailerPipe($this->getMailerMock(false)); - $result = ProcessResult::new(); - $mail = new Mail(); - $this->assertTrue($pipe->process($mail, $result)->failed()); - }); - - $this->specify('send failed, check info', function () { - $pipe = new MailerPipe($this->getMailerMock(false, 'errorinfo')); - $result = ProcessResult::new(); - $mail = new Mail(); - $result = $pipe->process($mail, $result); - $this->assertTrue($result->failed()); - $this->assertTrue($result->hasInfoFor(get_class($pipe))); - $this->assertEquals('errorinfo', $result->getInfo(get_class($pipe))); - }); - - $this->specify('pass on already errored result', function () { - $pipe = new MailerPipe($this->getMailerMock(true)); - $result = ProcessResult::new(); - $result->setStatus(ProcessResult::ERRORED); - $mail = new Mail(); - $this->assertTrue($pipe->process($mail, $result)->errored()); - }); - } - - /** - * @param bool $sendResponse - * @param string $errorinfo - * - * @return MailerInterface - */ - private function getMailerMock(bool $sendResponse, string $errorinfo = ''): MailerInterface - { - $mock = $this->getMockBuilder(MailerInterface::class)->setMethods(['send', 'getErrorInfo'])->getMock(); - $mock->method('send')->willReturn($sendResponse); - $mock->method('getErrorInfo')->willReturn($errorinfo); - - /**@var MailerInterface $mock */ - return $mock; - } -} \ No newline at end of file diff --git a/tests/Pipeline/ProcessResultTest.php b/tests/Pipeline/ProcessResultTest.php deleted file mode 100644 index d22ce11..0000000 --- a/tests/Pipeline/ProcessResultTest.php +++ /dev/null @@ -1,77 +0,0 @@ -specify('none', function () { - $result = ProcessResult::new(); - $this->assertFalse($result->succeeded()); - $this->assertFalse($result->errored()); - $this->assertFalse($result->failed()); - }); - - $this->specify('succeeded', function () { - $result = ProcessResult::new()->setStatus(ProcessResult::SUCCEEDED); - $this->assertTrue($result->succeeded()); - $this->assertFalse($result->errored()); - $this->assertFalse($result->failed()); - }); - - $this->specify('errored', function () { - $result = ProcessResult::new()->setStatus(ProcessResult::ERRORED); - $this->assertFalse($result->succeeded()); - $this->assertTrue($result->errored()); - $this->assertFalse($result->failed()); - }); - - $this->specify('failed', function () { - $result = ProcessResult::new()->setStatus(ProcessResult::FAILED); - $this->assertFalse($result->succeeded()); - $this->assertFalse($result->errored()); - $this->assertTrue($result->failed()); - }); - } - - public function testInfo() - { - $result = ProcessResult::new(); - $this->assertFalse($result->hasInfoFor('test')); - $result->addInfo('test', 'This is the Info'); - $this->assertTrue($result->hasInfoFor('test')); - $this->assertEquals('This is the Info', $result->getInfo('test')); - } - - public function testAttributes() - { - $this->specify('attribute doesnt exist', function () { - $result = ProcessResult::new(); - $this->assertFalse($result->hasAttribute('test')); - }); - - $this->specify('attribute doesnt exist, get throws exception', function () { - $result = ProcessResult::new(); - $this->expectException(Exception::class); - $result->getAttribute('test'); - }); - - $this->specify('attribute exist', function () { - $result = ProcessResult::new()->withAttribute('test', 'my Content'); - $this->assertTrue($result->hasAttribute('test')); - $this->assertEquals('my Content', $result->getAttribute('test')); - }); - } -} \ No newline at end of file From bdbb353af372413290c8a9d2305bf04a38420381 Mon Sep 17 00:00:00 2001 From: Sascha Date: Mon, 11 Jun 2018 10:48:49 +0200 Subject: [PATCH 2/6] removed unused using --- src/Mail.php | 1 - tests/MailTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Mail.php b/src/Mail.php index e97629f..9e7145d 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -5,7 +5,6 @@ use Conversio\Mail\Address\Address; use Conversio\Mail\Address\AddressContainer; use Conversio\Mail\Attachment\AttachmentContainer; -use DateTime; use Exception; /** diff --git a/tests/MailTest.php b/tests/MailTest.php index a53bbf0..db1f1ac 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -7,7 +7,6 @@ use Conversio\Mail\Attachment\AttachmentContainer; use Conversio\Mail\Content; use Conversio\Mail\Mail; -use DateTime; use PHPUnit\Framework\TestCase; /** From d53ae65457b988c677409499b33baf793411caa5 Mon Sep 17 00:00:00 2001 From: Sascha Date: Mon, 11 Jun 2018 14:37:46 +0200 Subject: [PATCH 3/6] possibility to clear container --- src/Container/AbstractContainer.php | 5 +++++ tests/Address/AddressContainerTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Container/AbstractContainer.php b/src/Container/AbstractContainer.php index 9d55c88..1f7b9c6 100644 --- a/src/Container/AbstractContainer.php +++ b/src/Container/AbstractContainer.php @@ -36,4 +36,9 @@ public function asArray(): array { return $this->store; } + + public function clear(): void + { + $this->store = []; + } } \ No newline at end of file diff --git a/tests/Address/AddressContainerTest.php b/tests/Address/AddressContainerTest.php index 98d34d6..11ad9b1 100644 --- a/tests/Address/AddressContainerTest.php +++ b/tests/Address/AddressContainerTest.php @@ -65,4 +65,14 @@ public function testAsArray() $this->assertCount(3, $container->asArray()); } + + public function testClear() + { + $container = new AddressContainer(); + $container->addAddress(new Address('test@example.com', 'Testmail')); + $this->assertEquals(1, $container->count()); + + $container->clear(); + $this->assertEquals(0, $container->count()); + } } \ No newline at end of file From af6cf8aa07269817b868b3a9784e59e3dee529a9 Mon Sep 17 00:00:00 2001 From: Sascha Date: Mon, 11 Jun 2018 16:09:14 +0200 Subject: [PATCH 4/6] added control-methods --- src/Content.php | 16 ++++++++++++++++ tests/ContentTest.php | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/Content.php b/src/Content.php index db73586..e83f48b 100644 --- a/src/Content.php +++ b/src/Content.php @@ -49,4 +49,20 @@ public function setText(string $text) { $this->text = $text; } + + /** + * @return bool + */ + public function hasHtmlContent(): bool + { + return $this->html !== ''; + } + + /** + * @return bool + */ + public function hasTextContent(): bool + { + return $this->text !== ''; + } } \ No newline at end of file diff --git a/tests/ContentTest.php b/tests/ContentTest.php index bccd802..8be167a 100644 --- a/tests/ContentTest.php +++ b/tests/ContentTest.php @@ -15,15 +15,19 @@ public function testGetHtml() { $content = new Content(); $this->assertEquals('', $content->getHtml()); + $this->assertFalse($content->hasHtmlContent()); $content->setHtml('Dies ist ein Text'); $this->assertEquals('Dies ist ein Text', $content->getHtml()); + $this->assertTrue($content->hasHtmlContent()); } public function testGetText() { $content = new Content(); $this->assertEquals('', $content->getText()); + $this->assertFalse($content->hasTextContent()); $content->setText('Dies ist ein Text'); $this->assertEquals('Dies ist ein Text', $content->getText()); + $this->assertTrue($content->hasTextContent()); } } \ No newline at end of file From 00396396aebc36e4a8f587c55aa841316a9d5865 Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 12 Jun 2018 14:44:21 +0200 Subject: [PATCH 5/6] rename Method --- src/Mail.php | 2 +- tests/MailTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mail.php b/src/Mail.php index 9e7145d..a67c383 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -93,7 +93,7 @@ public function setFrom(Address $from) * @return Address * @throws Exception */ - public function getFrom(): Address + public function from(): Address { if (!$this->hasFrom()) { throw new Exception('There is no from given'); diff --git a/tests/MailTest.php b/tests/MailTest.php index db1f1ac..0bbfd2b 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -45,7 +45,7 @@ public function testGetFrom() { $mail = new Mail(); $mail->setFrom(new Address('john.doe@test.de', 'John Doe')); - $this->assertTrue($mail->getFrom()->equals(new Address('john.doe@test.de', 'John Doe'))); + $this->assertTrue($mail->from()->equals(new Address('john.doe@test.de', 'John Doe'))); } /** From 386e69b0800bbcd169e2ff2ad7488e598da48554 Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 13 Jun 2018 12:09:48 +0200 Subject: [PATCH 6/6] json serializable --- src/Address/Address.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Address/Address.php b/src/Address/Address.php index b6dab64..95120f9 100644 --- a/src/Address/Address.php +++ b/src/Address/Address.php @@ -6,7 +6,7 @@ * Class Address * @package Conversio\Mail\Address */ -class Address +class Address implements \JsonSerializable { /** * @var string $address @@ -65,4 +65,16 @@ public function equals(self $address): bool { return $this->getAddress() === $address->getAddress(); } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + return get_object_vars($this); + } } \ No newline at end of file