2727
2828class TestCommand extends Command
2929{
30- use Configureable;
30+ use Configureable {
31+ Configureable::initialize as configureableInitialize;
32+ }
3133
3234 /** @noinspection ClassOverridesFieldOfSuperClassInspection */
3335 protected $ signature = <<<'SIGNATURE'
3436 exception-notify:test
35- {--c|channel=* : Specify channel to test}
36- {--j|job-connection=* : Specify job connection to test}
37+ {--c|channel= : Specify channel to test}
3738 SIGNATURE;
3839
3940 /** @noinspection ClassOverridesFieldOfSuperClassInspection */
@@ -43,14 +44,21 @@ public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
4344 {
4445 $ this ->output ->info ('Test for exception-notify start. ' );
4546
46- if (!config ('exception-notify.enabled ' )) {
47- $ this ->output ->warning (' The exception-notify is not enabled . Please enable it first. ' );
47+ if (!config ($ configurationKey = 'exception-notify.enabled ' )) {
48+ $ this ->output ->warning (" The configuration [ $ configurationKey ] is false . Please configure it to true. " );
4849
4950 return self ::INVALID ;
5051 }
5152
52- if (blank (config ('exception-notify.default ' ))) {
53- $ this ->output ->warning ('The exception-notify default channel is empty. Please configure it first. ' );
53+ if (!app ()->environment ($ environments = config ('exception-notify.environments ' ))) {
54+ $ this ->output ->warning (\sprintf (
55+ <<<'warning'
56+ The current environment is [%s], which is not in the configuration [%s].
57+ Please check the configuration.
58+ warning,
59+ app ()->environment (),
60+ implode ('、 ' , $ environments )
61+ ));
5462
5563 return self ::INVALID ;
5664 }
@@ -63,7 +71,7 @@ public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
6371 The exception [%s] should not be reported.
6472 Please check the configuration.
6573 warning,
66- RuntimeException ::class
74+ $ runtimeException ::class
6775 ));
6876
6977 return self ::INVALID ;
@@ -73,11 +81,12 @@ public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
7381 throw $ runtimeException ;
7482 } finally {
7583 $ this ->laravel ->terminating (function (): void {
76- $ this ->output ->section ($ default = \sprintf ('Current default channel: %s ' , config ('exception-notify.default ' )));
84+ $ this ->output ->section (\sprintf ('The current channel: %s ' , $ default = config ('exception-notify.default ' )));
85+ $ this ->output ->section (\sprintf ('The current job : %s ' , config ('exception-notify.job.connection ' )));
7786 $ this ->output ->warning (\sprintf (
7887 <<<'warning'
7988 An exception has been thrown to trigger the exception notification monitor.
80- Please check whether your channel(%s) received the exception notification reports.
89+ Please check whether your channel [%s] received the exception notification reports.
8190 If not, please find reason in the default log.
8291 warning,
8392 $ default
@@ -89,14 +98,16 @@ public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
8998
9099 /**
91100 * @noinspection MethodVisibilityInspection
101+ * @noinspection PhpMissingParentCallCommonInspection
92102 */
93103 protected function initialize (InputInterface $ input , OutputInterface $ output ): void
94104 {
105+ $ this ->configureableInitialize ($ input , $ output );
106+
95107 $ channel = $ this ->option ('channel ' ) and config ()->set ('exception-notify.default ' , $ channel );
96- $ connection = $ this ->option ('job-connection ' ) and config ()->set ('exception-notify.job.connection ' , $ connection );
97108
98- collect (config ('exception-notify.channels ' ))->each (static function (array $ config , string $ name ): void {
99- if ('notify ' === ($ config ['driver ' ] ?? $ name )) {
109+ collect (config ('exception-notify.channels ' ))->each (static function (array $ configuration , string $ name ): void {
110+ if ('notify ' === ($ configuration ['driver ' ] ?? $ name )) {
100111 config ()->set (
101112 "exception-notify.channels. $ name.client.extender " ,
102113 static fn (Client $ client ): Client => $ client
0 commit comments