44
55namespace App \Tests \Functional ;
66
7+ use App \Command \AskForInputCommand ;
78use App \Command \ExampleCommand ;
89use App \Tests \Support \FunctionalTester ;
10+ use Symfony \Component \Console \Command \Command ;
11+ use Symfony \Component \Console \Exception \MissingInputException ;
912
1013final class ConsoleCest
1114{
12- public function runSymfonyConsoleCommand (FunctionalTester $ I )
15+ public function runSymfonyConsoleCommand (FunctionalTester $ I ): void
1316 {
1417 // Call Symfony console without option
1518 $ output = $ I ->runSymfonyConsoleCommand (ExampleCommand::getDefaultName ());
@@ -29,4 +32,31 @@ public function runSymfonyConsoleCommand(FunctionalTester $I)
2932 );
3033 $ I ->assertStringContainsString ('Bye world! ' , $ output );
3134 }
35+
36+ public function runSymfonyConsoleCommandInput (FunctionalTester $ I ): void
37+ {
38+ // Confirmation question not confirmed
39+ $ output = $ I ->runSymfonyConsoleCommand (
40+ AskForInputCommand::getDefaultName (),
41+ consoleInputs: ['n ' ],
42+ expectedExitCode: Command::FAILURE ,
43+ );
44+ $ I ->assertStringContainsString ('bye ' , $ output );
45+
46+ // Exception on missing input
47+ $ I ->expectThrowable (
48+ MissingInputException::class,
49+ fn () => $ I ->runSymfonyConsoleCommand (
50+ AskForInputCommand::getDefaultName (),
51+ consoleInputs: ['y ' ],
52+ ),
53+ );
54+
55+ // Multiple inputs
56+ $ output = $ I ->runSymfonyConsoleCommand (
57+ AskForInputCommand::getDefaultName (),
58+ consoleInputs: ['y ' , 'foobar ' ],
59+ );
60+ $ I ->assertStringContainsString ("user input: 'foobar' " , $ output );
61+ }
3262}
0 commit comments