4
4
5
5
namespace App \Tests \Functional ;
6
6
7
+ use App \Command \AskForInputCommand ;
7
8
use App \Command \ExampleCommand ;
8
9
use App \Tests \Support \FunctionalTester ;
10
+ use Symfony \Component \Console \Command \Command ;
11
+ use Symfony \Component \Console \Exception \MissingInputException ;
9
12
10
13
final class ConsoleCest
11
14
{
12
- public function runSymfonyConsoleCommand (FunctionalTester $ I )
15
+ public function runSymfonyConsoleCommand (FunctionalTester $ I ): void
13
16
{
14
17
// Call Symfony console without option
15
18
$ output = $ I ->runSymfonyConsoleCommand (ExampleCommand::getDefaultName ());
@@ -29,4 +32,31 @@ public function runSymfonyConsoleCommand(FunctionalTester $I)
29
32
);
30
33
$ I ->assertStringContainsString ('Bye world! ' , $ output );
31
34
}
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
+ }
32
62
}
0 commit comments