@@ -229,8 +229,8 @@ public function testAddCommandWithEmptyConstructor()
229229 {
230230 $ this ->expectException (\LogicException::class);
231231 $ this ->expectExceptionMessage ('Command class "Foo5Command" is not correctly initialized. You probably forgot to call the parent constructor. ' );
232- $ application = new Application ();
233- $ application ->add (new \Foo5Command ());
232+
233+ ( new Application ()) ->add (new \Foo5Command ());
234234 }
235235
236236 public function testHasGet ()
@@ -294,8 +294,8 @@ public function testGetInvalidCommand()
294294 {
295295 $ this ->expectException (CommandNotFoundException::class);
296296 $ this ->expectExceptionMessage ('The command "foofoo" does not exist. ' );
297- $ application = new Application ();
298- $ application ->get ('foofoo ' );
297+
298+ ( new Application ()) ->get ('foofoo ' );
299299 }
300300
301301 public function testGetNamespaces ()
@@ -351,20 +351,21 @@ public function testFindInvalidNamespace()
351351 {
352352 $ this ->expectException (NamespaceNotFoundException::class);
353353 $ this ->expectExceptionMessage ('There are no commands defined in the "bar" namespace. ' );
354- $ application = new Application ();
355- $ application ->findNamespace ('bar ' );
354+
355+ ( new Application ) ->findNamespace ('bar ' );
356356 }
357357
358358 public function testFindUniqueNameButNamespaceName ()
359359 {
360- $ this ->expectException (CommandNotFoundException::class);
361- $ this ->expectExceptionMessage ('Command "foo1" is not defined ' );
362360 $ application = new Application ();
363361 $ application ->add (new \FooCommand ());
364362 $ application ->add (new \Foo1Command ());
365363 $ application ->add (new \Foo2Command ());
366364
367- $ application ->find ($ commandName = 'foo1 ' );
365+ $ this ->expectException (CommandNotFoundException::class);
366+ $ this ->expectExceptionMessage ('Command "foo1" is not defined ' );
367+
368+ $ application ->find ('foo1 ' );
368369 }
369370
370371 public function testFind ()
@@ -403,13 +404,14 @@ public function testFindCaseInsensitiveAsFallback()
403404
404405 public function testFindCaseInsensitiveSuggestions ()
405406 {
406- $ this ->expectException (CommandNotFoundException::class);
407- $ this ->expectExceptionMessage ('Command "FoO:BaR" is ambiguous ' );
408407 $ application = new Application ();
409408 $ application ->add (new \FooSameCaseLowercaseCommand ());
410409 $ application ->add (new \FooSameCaseUppercaseCommand ());
411410
412- $ this ->assertInstanceOf (\FooSameCaseLowercaseCommand::class, $ application ->find ('FoO:BaR ' ), '->find() will find two suggestions with case insensitivity ' );
411+ $ this ->expectException (CommandNotFoundException::class);
412+ $ this ->expectExceptionMessage ('Command "FoO:BaR" is ambiguous ' );
413+
414+ $ application ->find ('FoO:BaR ' );
413415 }
414416
415417 public function testFindWithCommandLoader ()
@@ -506,10 +508,12 @@ public function testFindCommandWithMissingNamespace()
506508 */
507509 public function testFindAlternativeExceptionMessageSingle ($ name )
508510 {
509- $ this ->expectException (CommandNotFoundException::class);
510- $ this ->expectExceptionMessage ('Did you mean this ' );
511511 $ application = new Application ();
512512 $ application ->add (new \Foo3Command ());
513+
514+ $ this ->expectException (CommandNotFoundException::class);
515+ $ this ->expectExceptionMessage ('Did you mean this ' );
516+
513517 $ application ->find ($ name );
514518 }
515519
@@ -744,11 +748,13 @@ public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
744748
745749 public function testFindWithDoubleColonInNameThrowsException ()
746750 {
747- $ this ->expectException (CommandNotFoundException::class);
748- $ this ->expectExceptionMessage ('Command "foo::bar" is not defined. ' );
749751 $ application = new Application ();
750752 $ application ->add (new \FooCommand ());
751753 $ application ->add (new \Foo4Command ());
754+
755+ $ this ->expectException (CommandNotFoundException::class);
756+ $ this ->expectExceptionMessage ('Command "foo::bar" is not defined. ' );
757+
752758 $ application ->find ('foo::bar ' );
753759 }
754760
@@ -1248,8 +1254,6 @@ public function testRunReturnsExitCodeOneForNegativeExceptionCode($exceptionCode
12481254
12491255 public function testAddingOptionWithDuplicateShortcut ()
12501256 {
1251- $ this ->expectException (\LogicException::class);
1252- $ this ->expectExceptionMessage ('An option with shortcut "e" already exists. ' );
12531257 $ dispatcher = new EventDispatcher ();
12541258 $ application = new Application ();
12551259 $ application ->setAutoExit (false );
@@ -1268,6 +1272,9 @@ public function testAddingOptionWithDuplicateShortcut()
12681272 $ input = new ArrayInput (['command ' => 'foo ' ]);
12691273 $ output = new NullOutput ();
12701274
1275+ $ this ->expectException (\LogicException::class);
1276+ $ this ->expectExceptionMessage ('An option with shortcut "e" already exists. ' );
1277+
12711278 $ application ->run ($ input , $ output );
12721279 }
12731280
@@ -1276,7 +1283,6 @@ public function testAddingOptionWithDuplicateShortcut()
12761283 */
12771284 public function testAddingAlreadySetDefinitionElementData ($ def )
12781285 {
1279- $ this ->expectException (\LogicException::class);
12801286 $ application = new Application ();
12811287 $ application ->setAutoExit (false );
12821288 $ application ->setCatchExceptions (false );
@@ -1288,10 +1294,13 @@ public function testAddingAlreadySetDefinitionElementData($def)
12881294
12891295 $ input = new ArrayInput (['command ' => 'foo ' ]);
12901296 $ output = new NullOutput ();
1297+
1298+ $ this ->expectException (\LogicException::class);
1299+
12911300 $ application ->run ($ input , $ output );
12921301 }
12931302
1294- public static function getAddingAlreadySetDefinitionElementData ()
1303+ public static function getAddingAlreadySetDefinitionElementData (): array
12951304 {
12961305 return [
12971306 [new InputArgument ('command ' , InputArgument::REQUIRED )],
@@ -1428,8 +1437,6 @@ public function testRunWithDispatcher()
14281437
14291438 public function testRunWithExceptionAndDispatcher ()
14301439 {
1431- $ this ->expectException (\LogicException::class);
1432- $ this ->expectExceptionMessage ('error ' );
14331440 $ application = new Application ();
14341441 $ application ->setDispatcher ($ this ->getDispatcher ());
14351442 $ application ->setAutoExit (false );
@@ -1440,6 +1447,10 @@ public function testRunWithExceptionAndDispatcher()
14401447 });
14411448
14421449 $ tester = new ApplicationTester ($ application );
1450+
1451+ $ this ->expectException (\LogicException::class);
1452+ $ this ->expectExceptionMessage ('error ' );
1453+
14431454 $ tester ->run (['command ' => 'foo ' ]);
14441455 }
14451456
@@ -1504,9 +1515,6 @@ public function testRunWithError()
15041515
15051516 public function testRunWithFindError ()
15061517 {
1507- $ this ->expectException (\Error::class);
1508- $ this ->expectExceptionMessage ('Find exception ' );
1509-
15101518 $ application = new Application ();
15111519 $ application ->setAutoExit (false );
15121520 $ application ->setCatchExceptions (false );
@@ -1518,6 +1526,10 @@ public function testRunWithFindError()
15181526
15191527 // The exception should not be ignored
15201528 $ tester = new ApplicationTester ($ application );
1529+
1530+ $ this ->expectException (\Error::class);
1531+ $ this ->expectExceptionMessage ('Find exception ' );
1532+
15211533 $ tester ->run (['command ' => 'foo ' ]);
15221534 }
15231535
@@ -1590,8 +1602,6 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
15901602
15911603 public function testRunWithErrorAndDispatcher ()
15921604 {
1593- $ this ->expectException (\LogicException::class);
1594- $ this ->expectExceptionMessage ('error ' );
15951605 $ application = new Application ();
15961606 $ application ->setDispatcher ($ this ->getDispatcher ());
15971607 $ application ->setAutoExit (false );
@@ -1604,6 +1614,10 @@ public function testRunWithErrorAndDispatcher()
16041614 });
16051615
16061616 $ tester = new ApplicationTester ($ application );
1617+
1618+ $ this ->expectException (\LogicException::class);
1619+ $ this ->expectExceptionMessage ('error ' );
1620+
16071621 $ tester ->run (['command ' => 'dym ' ]);
16081622 $ this ->assertStringContainsString ('before.dym.error.after. ' , $ tester ->getDisplay (), 'The PHP error did not dispatch events ' );
16091623 }
@@ -1802,9 +1816,11 @@ public function testRunLazyCommandService()
18021816
18031817 public function testGetDisabledLazyCommand ()
18041818 {
1805- $ this ->expectException (CommandNotFoundException::class);
18061819 $ application = new Application ();
18071820 $ application ->setCommandLoader (new FactoryCommandLoader (['disabled ' => fn () => new DisabledCommand ()]));
1821+
1822+ $ this ->expectException (CommandNotFoundException::class);
1823+
18081824 $ application ->get ('disabled ' );
18091825 }
18101826
@@ -1895,8 +1911,6 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn
18951911
18961912 public function testThrowingErrorListener ()
18971913 {
1898- $ this ->expectException (\RuntimeException::class);
1899- $ this ->expectExceptionMessage ('foo ' );
19001914 $ dispatcher = $ this ->getDispatcher ();
19011915 $ dispatcher ->addListener ('console.error ' , function (ConsoleErrorEvent $ event ) {
19021916 throw new \RuntimeException ('foo ' );
@@ -1916,20 +1930,25 @@ public function testThrowingErrorListener()
19161930 });
19171931
19181932 $ tester = new ApplicationTester ($ application );
1933+
1934+ $ this ->expectException (\RuntimeException::class);
1935+ $ this ->expectExceptionMessage ('foo ' );
1936+
19191937 $ tester ->run (['command ' => 'foo ' ]);
19201938 }
19211939
19221940 public function testCommandNameMismatchWithCommandLoaderKeyThrows ()
19231941 {
1924- $ this ->expectException (CommandNotFoundException::class);
1925- $ this ->expectExceptionMessage ('The "test" command cannot be found because it is registered under multiple names. Make sure you don \'t set a different name via constructor or "setName()". ' );
1926-
19271942 $ app = new Application ();
19281943 $ loader = new FactoryCommandLoader ([
19291944 'test ' => static fn () => new Command ('test-command ' ),
19301945 ]);
19311946
19321947 $ app ->setCommandLoader ($ loader );
1948+
1949+ $ this ->expectException (CommandNotFoundException::class);
1950+ $ this ->expectExceptionMessage ('The "test" command cannot be found because it is registered under multiple names. Make sure you don \'t set a different name via constructor or "setName()". ' );
1951+
19331952 $ app ->get ('test ' );
19341953 }
19351954
0 commit comments