From 68b3d751a86c5c2de6b70ea59780f16bd28c6468 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sun, 24 Mar 2024 12:18:59 +0100 Subject: [PATCH 1/2] Use mail from name even if it was not specified --- src/EmailComposer.php | 12 +++++++----- tests/MailableReaderTest.php | 2 +- tests/SenderTest.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/EmailComposer.php b/src/EmailComposer.php index fc4d67c..1edb0aa 100644 --- a/src/EmailComposer.php +++ b/src/EmailComposer.php @@ -152,13 +152,15 @@ public function send(): Email (new MailableReader())->read($this); } - if (! $this->email->from) { - $this->email->from = [ - 'address' => config('mail.from.address'), - 'name' => config('mail.from.name'), - ]; + if (! is_array($this->email->from)) { + $this->email->from = []; } + $this->email->from = [ + 'name' => $this->email->from['name'] ?? config('mail.from.name'), + 'address' => $this->email->from['address'] ?? config('mail.from.address'), + ]; + $this->email->save(); $this->email->refresh(); diff --git a/tests/MailableReaderTest.php b/tests/MailableReaderTest.php index 7e15865..6f49725 100644 --- a/tests/MailableReaderTest.php +++ b/tests/MailableReaderTest.php @@ -106,7 +106,7 @@ public function it_extracts_the_from_address_and_or_name() $this->assertTrue((bool) $email->from); $this->assertEquals('marick@dolphiq.nl', $email->from['address']); - $this->assertEquals(null, $email->from['name']); + $this->assertEquals('Example', $email->from['name']); $email = Email::compose()->mailable( ($this->mailable()) diff --git a/tests/SenderTest.php b/tests/SenderTest.php index 7083b01..be8a295 100644 --- a/tests/SenderTest.php +++ b/tests/SenderTest.php @@ -68,7 +68,7 @@ public function the_email_has_a_correct_from_email_and_from_name() $this->artisan('email:send'); $from = reset($this->sent)->from; $this->assertEquals('marick@dolphiq.nl', key($from)); - $this->assertEquals(null, $from[key($from)]); + $this->assertEquals('From CI test', $from[key($from)]); } #[Test] From c1b30e632604ae4ceae7d609b1e07e507b6b1a51 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sun, 24 Mar 2024 12:26:12 +0100 Subject: [PATCH 2/2] Fix --- tests/MailableReaderTest.php | 2 +- tests/TestCase.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/MailableReaderTest.php b/tests/MailableReaderTest.php index 6f49725..42a5e6b 100644 --- a/tests/MailableReaderTest.php +++ b/tests/MailableReaderTest.php @@ -106,7 +106,7 @@ public function it_extracts_the_from_address_and_or_name() $this->assertTrue((bool) $email->from); $this->assertEquals('marick@dolphiq.nl', $email->from['address']); - $this->assertEquals('Example', $email->from['name']); + $this->assertEquals('Laravel', $email->from['name']); $email = Email::compose()->mailable( ($this->mailable()) diff --git a/tests/TestCase.php b/tests/TestCase.php index 08dbe88..abd3a67 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -86,6 +86,8 @@ protected function getEnvironmentSetUp($app) ]); $app['config']->set('mail.driver', 'log'); + + $app['config']->set('mail.from.name', 'Laravel'); } public function createEmail($overwrite = [])