diff --git a/component/Time/Date.php b/component/Time/Date.php index b116cbe..33cf93b 100644 --- a/component/Time/Date.php +++ b/component/Time/Date.php @@ -22,7 +22,7 @@ public function __construct( $time = is_string($date) ? strtotime($date) : $date; - if (!is_a($this, DateTime::class)) { + if (!is_a($this, DateTime::class) && $time) { $time = (new \DateTime())->setTimestamp($time)->setTime(0, 0)->getTimestamp(); } diff --git a/component/Web/Email.php b/component/Web/Email.php index 6e03115..57740eb 100644 --- a/component/Web/Email.php +++ b/component/Web/Email.php @@ -25,9 +25,9 @@ public static function make( string $messageTxt, string $messageHtml, string $fromEmailAddress, - string $fromName, + ?string $fromName, string $toEmailAddress, - string $toName, + ?string $toName, ?string $replyToEmailAddress = null, ?string $replyToName = null, ?EmailAttachmentList $attachmentList = null diff --git a/test/Web/EmailTest.php b/test/Web/EmailTest.php index 0f8624a..b2cd3e7 100644 --- a/test/Web/EmailTest.php +++ b/test/Web/EmailTest.php @@ -122,4 +122,42 @@ public function testMake(): void $this->assertIsObject($email->attachmentList); $this->assertInstanceOf(EmailAttachmentList::class, $email->attachmentList); } + + public function testMakeBasic(): void + { + $email = Email::make( + 'Subject', + 'Message', + '
Message
', + 'contact@acme.ext', + null, + 'john.doe@domain.ext', + null + ); + + $this->assertInstanceOf(Email::class, $email); + + $this->assertIsString($email->subject); + $this->assertEquals('Subject', $email->subject); + + $this->assertIsString($email->messageTxt); + $this->assertEquals('Message', $email->messageTxt); + + $this->assertIsString($email->messageHtml); + $this->assertEquals('Message
', $email->messageHtml); + + $this->assertIsObject($email->from); + $this->assertInstanceOf(EmailAddressAndName::class, $email->from); + $this->assertEquals('contact@acme.ext', (string)$email->from->emailAddress); + $this->assertNull($email->from->name); + + $this->assertIsObject($email->to); + $this->assertInstanceOf(EmailAddressAndName::class, $email->to); + $this->assertEquals('john.doe@domain.ext', (string)$email->to->emailAddress); + $this->assertNull($email->to->name); + + $this->assertNull($email->replyTo); + + $this->assertNull($email->attachmentList); + } }