diff --git a/src/Address/Address.php b/src/Address/Address.php
index 4e2e5b1..95120f9 100644
--- a/src/Address/Address.php
+++ b/src/Address/Address.php
@@ -1,10 +1,4 @@
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
diff --git a/src/Address/AddressContainer.php b/src/Address/AddressContainer.php
index 7edc3df..924c971 100644
--- a/src/Address/AddressContainer.php
+++ b/src/Address/AddressContainer.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 @@
store;
}
+
+ public function clear(): void
+ {
+ $this->store = [];
+ }
}
\ No newline at end of file
diff --git a/src/Content.php b/src/Content.php
index b84b612..e83f48b 100644
--- a/src/Content.php
+++ b/src/Content.php
@@ -1,10 +1,4 @@
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/src/Mail.php b/src/Mail.php
index 1ccd1e7..a67c383 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;
/**
@@ -15,14 +14,14 @@
class Mail
{
/**
- * @var string $id
+ * @var Address
*/
- private $id = '';
+ private $sender;
/**
* @var Address
*/
- private $sender;
+ private $from;
/**
* @var string
@@ -54,11 +53,6 @@ class Mail
*/
private $attachments;
- /**
- * @var DateTime
- */
- private $createdAt;
-
/**
* @var AddressContainer
*/
@@ -67,9 +61,8 @@ class Mail
/**
* Mail constructor.
*
- * @param DateTime|null $createdAt
*/
- public function __construct(DateTime $createdAt = null)
+ public function __construct()
{
$this->content = new Content();
$this->recipients = new AddressContainer();
@@ -77,7 +70,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 +80,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 from(): 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 +118,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 +171,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..11ad9b1 100644
--- a/tests/Address/AddressContainerTest.php
+++ b/tests/Address/AddressContainerTest.php
@@ -1,10 +1,4 @@
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
diff --git a/tests/Assistant/AssistantTest.php b/tests/Assistant/AssistantTest.php
deleted file mode 100644
index 5a95f94..0000000
--- a/tests/Assistant/AssistantTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
-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..8be167a 100644
--- a/tests/ContentTest.php
+++ b/tests/ContentTest.php
@@ -1,12 +1,5 @@
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
diff --git a/tests/MailTest.php b/tests/MailTest.php
index 61a961b..0bbfd2b 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;
/**
@@ -16,20 +15,6 @@
*/
class MailTest extends TestCase
{
- public function testGetId()
- {
- $mail = new Mail();
- $mail->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 +32,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->from()->equals(new Address('john.doe@test.de', 'John Doe')));
+ }
+
/**
* @return Mail
*/
@@ -88,10 +80,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