From 6bf1be979c0e114df5d05ccb4dc02fde4b5ba96d Mon Sep 17 00:00:00 2001 From: Max Hoogenbosch Date: Sat, 22 Oct 2022 14:38:50 +0200 Subject: [PATCH 1/4] WIP --- tests/AlternativeMailTest.php | 17 +++++++++++++++++ tests/Mails/AlternativeMail.php | 28 ++++++++++++++++++++++++++++ tests/Mails/ClassicMail.php | 18 ++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/AlternativeMailTest.php create mode 100644 tests/Mails/AlternativeMail.php create mode 100644 tests/Mails/ClassicMail.php diff --git a/tests/AlternativeMailTest.php b/tests/AlternativeMailTest.php new file mode 100644 index 0000000..df50bca --- /dev/null +++ b/tests/AlternativeMailTest.php @@ -0,0 +1,17 @@ +subject())->toBe('Invoice Paid') + ->and($item->content())->toBe('Test mail content'); +}) + ->with([ + new ClassicMail(), + new AlternativeMail(), + ]) + ->skip(! class_exists('Illuminate\Mail\Mailables\Envelope'), 'Alternative mailables are not available in this version of Laravel'); diff --git a/tests/Mails/AlternativeMail.php b/tests/Mails/AlternativeMail.php new file mode 100644 index 0000000..ac8d0b1 --- /dev/null +++ b/tests/Mails/AlternativeMail.php @@ -0,0 +1,28 @@ +subject('Invoice Paid') + ->cc('foo@example.com', 'Example Name') + ->html('Test mail content'); + } +} From 60560cd6fd5530d16af24efa428159d126076e3b Mon Sep 17 00:00:00 2001 From: Max Hoogenbosch Date: Sun, 23 Oct 2022 15:56:02 +0200 Subject: [PATCH 2/4] Fixed phpstan --- tests/AlternativeMailTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AlternativeMailTest.php b/tests/AlternativeMailTest.php index df50bca..d6594b3 100644 --- a/tests/AlternativeMailTest.php +++ b/tests/AlternativeMailTest.php @@ -4,7 +4,7 @@ use Xammie\Mailbook\Tests\Mails\AlternativeMail; use Xammie\Mailbook\Tests\Mails\ClassicMail; -it('can get mail information', function ($mailable) { +it('can get mail content', function ($mailable) { $item = Mailbook::add($mailable); expect($item->subject())->toBe('Invoice Paid') From 185a8cafb41e80263de2fa6754f613f1fca09e0b Mon Sep 17 00:00:00 2001 From: Max Hoogenbosch Date: Sun, 23 Oct 2022 17:11:18 +0200 Subject: [PATCH 3/4] Fixed support for alternative syntax Tests will still fail, waiting on https://github.com/laravel/framework/pull/44696 --- src/MailableResolver.php | 8 ++++++++ tests/AlternativeMailTest.php | 9 +++++++-- tests/Mails/AlternativeMail.php | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/MailableResolver.php b/src/MailableResolver.php index 16dfd4d..7629591 100644 --- a/src/MailableResolver.php +++ b/src/MailableResolver.php @@ -16,6 +16,8 @@ class MailableResolver private ?string $content = null; + private bool $hasBuild = false; + public function __construct(public string|Closure|Mailable $mailable) { } @@ -92,6 +94,12 @@ public function content(): string private function build(Mailable $instance): Mailable { + if ($this->hasBuild) { + return $instance; + } + + $this->hasBuild = true; + $locale = MailbookFacade::getLocale(); if ($locale) { diff --git a/tests/AlternativeMailTest.php b/tests/AlternativeMailTest.php index d6594b3..482b7c5 100644 --- a/tests/AlternativeMailTest.php +++ b/tests/AlternativeMailTest.php @@ -4,11 +4,16 @@ use Xammie\Mailbook\Tests\Mails\AlternativeMail; use Xammie\Mailbook\Tests\Mails\ClassicMail; -it('can get mail content', function ($mailable) { +it('can get mail subject and content', function ($mailable) { $item = Mailbook::add($mailable); expect($item->subject())->toBe('Invoice Paid') - ->and($item->content())->toBe('Test mail content'); + ->and($item->content())->toBe('Test mail content') + ->and($item->from())->toBe(['Example ']) + ->and($item->replyTo())->toBe([]) + ->and($item->to())->toBe([]) + ->and($item->cc())->toBe(['Example Name ']) + ->and($item->bcc())->toBe([]); }) ->with([ new ClassicMail(), diff --git a/tests/Mails/AlternativeMail.php b/tests/Mails/AlternativeMail.php index ac8d0b1..5bd73c1 100644 --- a/tests/Mails/AlternativeMail.php +++ b/tests/Mails/AlternativeMail.php @@ -22,7 +22,7 @@ public function envelope(): Envelope public function content(): Content { return new Content( - text: 'Test mail content', + html: 'Test mail content', ); } } From f21424fa667d8c33b14bfa2d155b2fad96acfa05 Mon Sep 17 00:00:00 2001 From: Max Hoogenbosch Date: Tue, 25 Oct 2022 19:42:18 +0200 Subject: [PATCH 4/4] Fixed tests --- tests/Mails/AlternativeMail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mails/AlternativeMail.php b/tests/Mails/AlternativeMail.php index 5bd73c1..b751e32 100644 --- a/tests/Mails/AlternativeMail.php +++ b/tests/Mails/AlternativeMail.php @@ -22,7 +22,7 @@ public function envelope(): Envelope public function content(): Content { return new Content( - html: 'Test mail content', + htmlString: 'Test mail content', ); } }