20
20
use Symfony \Component \Console \Messenger \RunCommandMessage ;
21
21
use Symfony \Component \Console \Messenger \RunCommandMessageHandler ;
22
22
use Symfony \Component \Console \Output \OutputInterface ;
23
+ use Symfony \Component \Messenger \Exception \UnrecoverableExceptionInterface ;
24
+ use Symfony \Component \Messenger \Exception \UnrecoverableMessageHandlingException ;
23
25
24
26
/**
25
27
* @author Kevin Bond <kevinbond@gmail.com>
@@ -81,6 +83,22 @@ public function testThrowOnNonSuccess()
81
83
$ this ->fail ('Exception not thrown. ' );
82
84
}
83
85
86
+ public function testExecutesCommandThatThrownUnrecoverableException ()
87
+ {
88
+ $ handler = new RunCommandMessageHandler ($ this ->createApplicationWithCommand ());
89
+
90
+ try {
91
+ $ handler (new RunCommandMessage ('test:command --throw-unrecoverable ' ));
92
+ } catch (UnrecoverableExceptionInterface $ e ) {
93
+ $ this ->assertSame ('unrecoverable exception message ' , $ e ->getMessage ());
94
+ $ this ->assertNull ($ e ->getPrevious ());
95
+
96
+ return ;
97
+ }
98
+
99
+ $ this ->fail ('Exception not thrown. ' );
100
+ }
101
+
84
102
private function createApplicationWithCommand (): Application
85
103
{
86
104
$ application = new Application ();
@@ -92,6 +110,7 @@ public function configure(): void
92
110
$ this
93
111
->setName ('test:command ' )
94
112
->addOption ('throw ' )
113
+ ->addOption ('throw-unrecoverable ' )
95
114
->addOption ('exit ' , null , InputOption::VALUE_REQUIRED , 0 )
96
115
;
97
116
}
@@ -100,6 +119,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
100
119
{
101
120
$ output ->write ('some message ' );
102
121
122
+ if ($ input ->getOption ('throw-unrecoverable ' )) {
123
+ throw new UnrecoverableMessageHandlingException ('unrecoverable exception message ' );
124
+ }
125
+
103
126
if ($ input ->getOption ('throw ' )) {
104
127
throw new \RuntimeException ('exception message ' );
105
128
}
0 commit comments