Skip to content

Commit 8177d86

Browse files
committed
refactor: update TestCommand handle method
- Change the output note to a more appropriate message. - Use try-catch to handle the exception. - Provide a warning message on failure.
1 parent 427b31b commit 8177d86

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/Commands/TestCommand.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,30 @@ class TestCommand extends Command
2525

2626
public function handle(ExceptionNotifyManager $exceptionNotifyManager): void
2727
{
28-
$this->output->section('The main configuration is as follows:');
28+
$this->output->note('Test for exception-notify start.');
29+
$this->output->section('The main configuration is as follows.');
2930
$this->output->listing($this->getMainConfigurations());
3031

31-
$runtimeException = new RuntimeException(<<<'note'
32-
Test for exception-notify done.
33-
Please check whether your channels received the exception notification report.
34-
If not, please find reason in the default log.
35-
note);
36-
if ($exceptionNotifyManager->shouldReport($runtimeException)) {
37-
throw $runtimeException;
38-
}
32+
try {
33+
$runtimeException = new RuntimeException('Test for exception-notify.');
34+
if ($exceptionNotifyManager->shouldReport($runtimeException)) {
35+
throw $runtimeException;
36+
}
37+
38+
$warning = sprintf(
39+
'The exception [%s] should not be reported. Please check the configuration.',
40+
\get_class($runtimeException)
41+
);
42+
} finally {
43+
$this->output->warning(
44+
$warning ?? <<<'warning'
45+
Please check whether your channels received the exception notification report.
46+
If not, please find reason in the default log.
47+
warning
48+
);
3949

40-
$this->output->warning(sprintf(
41-
'The exception [%s] should not be reported. Please check the configuration.',
42-
\get_class($runtimeException)
43-
));
50+
$this->output->note('Test for exception-notify done.');
51+
}
4452
}
4553

4654
private function getMainConfigurations(): array

tests/Commands/TestCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222

2323
it('will throws RuntimeException', function (): void {
2424
artisan(TestCommand::class);
25-
})->group(__DIR__, __FILE__)->throws(RuntimeException::class, 'Test for exception-notify done.');
25+
})->group(__DIR__, __FILE__)->throws(RuntimeException::class, 'Test for exception-notify.');

0 commit comments

Comments
 (0)