|
15 | 15 | use Guanguans\LaravelExceptionNotify\ExceptionNotifyManager; |
16 | 16 | use Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException; |
17 | 17 | use Illuminate\Console\Command; |
18 | | -use Illuminate\Console\OutputStyle; |
19 | 18 | use Illuminate\Support\Arr; |
20 | | -use Symfony\Component\Console\Input\ArgvInput; |
21 | | -use Symfony\Component\Console\Output\ConsoleOutput; |
22 | 19 |
|
23 | 20 | class TestCommand extends Command |
24 | 21 | { |
25 | 22 | protected $signature = 'exception-notify:test'; |
26 | 23 |
|
27 | 24 | protected $description = 'Test for exception-notify'; |
28 | 25 |
|
29 | | - private ?string $warning = null; |
30 | | - |
31 | | - public function __destruct() |
32 | | - { |
33 | | - if (! $this->output instanceof OutputStyle) { |
34 | | - $this->output = new OutputStyle(new ArgvInput, new ConsoleOutput); |
35 | | - } |
36 | | - |
37 | | - if ($this->warning) { |
38 | | - $this->output->warning($this->warning); |
39 | | - |
40 | | - return; |
41 | | - } |
42 | | - |
43 | | - $this->output->newLine(); |
44 | | - $this->output->note( |
45 | | - <<<'note' |
46 | | - Test for exception-notify done. |
47 | | - Please check whether your channels received the exception notification report. |
48 | | - If not, please find reason in the default log. |
49 | | - note |
50 | | - ); |
51 | | - } |
52 | | - |
53 | 26 | public function handle(ExceptionNotifyManager $exceptionNotifyManager): void |
54 | 27 | { |
55 | | - $this->output->note('Test for exception-notify start.'); |
56 | | - $this->output->section('The current main configuration is as follows:'); |
| 28 | + $this->output->section('The main configuration is as follows:'); |
57 | 29 | $this->output->listing($this->getMainConfigurations()); |
58 | 30 |
|
59 | | - $runtimeException = new RuntimeException('Test for exception-notify.'); |
| 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); |
60 | 36 | if ($exceptionNotifyManager->shouldReport($runtimeException)) { |
61 | 37 | throw $runtimeException; |
62 | 38 | } |
63 | 39 |
|
64 | | - $this->warning = sprintf( |
| 40 | + $this->output->warning(sprintf( |
65 | 41 | 'The exception [%s] should not be reported. Please check the configuration.', |
66 | 42 | \get_class($runtimeException) |
67 | | - ); |
| 43 | + )); |
68 | 44 | } |
69 | 45 |
|
70 | 46 | private function getMainConfigurations(): array |
|
0 commit comments