File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1616use Ahc \Cli \IO \Interactor ;
1717use InvalidArgumentException ;
1818use PHPUnit \Framework \TestCase ;
19+ use Throwable ;
1920
2021class ApplicationTest extends TestCase
2122{
@@ -288,11 +289,19 @@ public function test_io_returns_new_instance_if_not_provided(): void
288289 );
289290 }
290291
292+ public function test_on_exception ()
293+ {
294+ $ this ->expectException (InvalidArgumentException::class);
295+ $ this ->expectExceptionMessage ($ msg = 'this will be rethrown and propagated ' );
296+
297+ $ cmd = (new Command ('cmd ' ))->action (fn () => throw new InvalidArgumentException ($ msg ));
298+ $ app = $ this ->newApp ('test ' )->add ($ cmd )->onException (fn (Throwable $ e ) => throw $ e );
299+ $ app ->handle (['test ' , 'cmd ' ]);
300+ }
301+
291302 protected function newApp (string $ name , string $ version = '' )
292303 {
293- $ app = new Application ($ name , $ version ?: '0.0.1 ' , function () {
294- return false ;
295- });
304+ $ app = new Application ($ name , $ version ?: '0.0.1 ' , fn () => false );
296305
297306 return $ app ->io (new Interactor (static ::$ in , static ::$ ou ));
298307 }
You can’t perform that action at this time.
0 commit comments