@@ -771,10 +771,15 @@ public function testFindAmbiguousCommandsIfAllAlternativesAreHidden()
771771 $ this ->assertInstanceOf (\FooCommand::class, $ application ->find ('foo: ' ));
772772 }
773773
774- public function testSetCatchExceptions ()
774+ /**
775+ * @testWith [true]
776+ * [false]
777+ */
778+ public function testSetCatchExceptions (bool $ catchErrors )
775779 {
776780 $ application = new Application ();
777781 $ application ->setAutoExit (false );
782+ $ application ->setCatchErrors ($ catchErrors );
778783 putenv ('COLUMNS=120 ' );
779784 $ tester = new ApplicationTester ($ application );
780785
@@ -798,6 +803,33 @@ public function testSetCatchExceptions()
798803 }
799804 }
800805
806+ /**
807+ * @testWith [true]
808+ * [false]
809+ */
810+ public function testSetCatchErrors (bool $ catchExceptions )
811+ {
812+ $ application = new Application ();
813+ $ application ->setAutoExit (false );
814+ $ application ->setCatchExceptions ($ catchExceptions );
815+ $ application ->add ((new Command ('boom ' ))->setCode (fn () => throw new \Error ('This is an error. ' )));
816+
817+ putenv ('COLUMNS=120 ' );
818+ $ tester = new ApplicationTester ($ application );
819+
820+ try {
821+ $ tester ->run (['command ' => 'boom ' ]);
822+ $ this ->fail ('The exception is not catched. ' );
823+ } catch (\Throwable $ e ) {
824+ $ this ->assertInstanceOf (\Error::class, $ e );
825+ $ this ->assertSame ('This is an error. ' , $ e ->getMessage ());
826+ }
827+
828+ $ application ->setCatchErrors (true );
829+ $ tester ->run (['command ' => 'boom ' ]);
830+ $ this ->assertStringContainsString (' This is an error. ' , $ tester ->getDisplay (true ));
831+ }
832+
801833 public function testAutoExitSetting ()
802834 {
803835 $ application = new Application ();
0 commit comments