From bde2da45f7737c640f7acbc7b2ccadf5ad3a6917 Mon Sep 17 00:00:00 2001 From: William Allen Date: Sun, 16 Aug 2026 16:17:28 -0400 Subject: [PATCH] Add `email:test` Artisan command This PR adds a new `php artisan email:test --email=` command which allows administrators to easily verify that email is configured correctly. Closes https://github.com/Kitware/CDash/issues/3727. --- app/Console/Commands/EmailTestCommand.php | 53 +++++++++++++++++++ app/Mail/TestEmail.php | 36 +++++++++++++ app/cdash/tests/CMakeLists.txt | 2 + .../email/email-configuration-test.blade.php | 3 ++ tests/Feature/EmailTestCommandTest.php | 48 +++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 app/Console/Commands/EmailTestCommand.php create mode 100644 app/Mail/TestEmail.php create mode 100644 resources/views/email/email-configuration-test.blade.php create mode 100644 tests/Feature/EmailTestCommandTest.php diff --git a/app/Console/Commands/EmailTestCommand.php b/app/Console/Commands/EmailTestCommand.php new file mode 100644 index 0000000000..2a24e2266d --- /dev/null +++ b/app/Console/Commands/EmailTestCommand.php @@ -0,0 +1,53 @@ +option('email'); + + $validator = Validator::make([ + 'email' => $email, + ], [ + 'email' => 'required|email', + ], [ + 'email.required' => 'You must specify the --email option', + 'email.email' => "Invalid email address: $email", + ]); + + if ($validator->fails()) { + foreach ($validator->errors()->all() as $error) { + $this->error($error); + } + return; + } + + Mail::to($email)->send(new TestEmail()); + + $this->info("Test email sent to $email"); + } +} diff --git a/app/Mail/TestEmail.php b/app/Mail/TestEmail.php new file mode 100644 index 0000000000..4eddd74fcc --- /dev/null +++ b/app/Mail/TestEmail.php @@ -0,0 +1,36 @@ + $email]); + + Mail::assertQueued(TestEmail::class, fn ($mail) => $mail->hasTo($email)); + + $output = trim(Artisan::output()); + $this->assertStringContainsString("Test email sent to $email", $output); + } + + public function testEmailTestCommandRequiresEmail(): void + { + Mail::fake(); + Artisan::call('email:test'); + $output = trim(Artisan::output()); + $this->assertStringContainsString('You must specify the --email option', $output); + Mail::assertNothingSent(); + Mail::assertNothingQueued(); + } + + public function testEmailTestCommandInvalidEmail(): void + { + Mail::fake(); + Artisan::call('email:test', ['--email' => 'not-an-email']); + $output = trim(Artisan::output()); + $this->assertStringContainsString('Invalid email address: not-an-email', $output); + Mail::assertNothingSent(); + Mail::assertNothingQueued(); + } +}