From 69b8a337c3749d27d5be9b4ff0fa13f866586d26 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 2 Apr 2024 15:23:52 +0200 Subject: [PATCH] Make `php artisan send-test-mail` option `--from` optional --- CHANGELOG.md | 6 ++++++ src/Mail/SendTestMailCommand.php | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 606ba79..95e2981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ See [GitHub releases](https://github.com/mll-lab/laravel-utils/releases). ## Unreleased +## v4.12.0 + +### Changed + +- Make `php artisan send-test-mail` option `--from` optional + ## v4.11.0 ### Added diff --git a/src/Mail/SendTestMailCommand.php b/src/Mail/SendTestMailCommand.php index cec2c3f..1469290 100644 --- a/src/Mail/SendTestMailCommand.php +++ b/src/Mail/SendTestMailCommand.php @@ -20,11 +20,13 @@ public function handle(): void $mail = new TestMail(); $from = $this->option('from'); - if (! is_string($from)) { - $fromType = gettype($from); - throw new \UnexpectedValueException("Expected option --from to be string, got {$fromType}."); + if (! is_null($from)) { + if (! is_string($from)) { // @phpstan-ignore-line option values can also be arrays + $fromType = gettype($from); + throw new \UnexpectedValueException("Expected option --from to be string, got {$fromType}."); + } + $mail->from($from); } - $mail->from($from); $to = $this->option('to'); if (! is_string($to)) {