66
77use Behat \Behat \Context \Context ;
88use Behat \Hook \BeforeScenario ;
9+ use Behat \Step \Given ;
910use Behat \Step \Then ;
1011use Behat \Step \When ;
1112use DomainException ;
@@ -23,6 +24,8 @@ class CommandContext implements Context
2324{
2425 private ?string $ output = null ;
2526 private ?int $ returnCode = null ;
27+ /** @var ?resource */
28+ private $ stream = null ;
2629
2730 public function __construct (
2831 protected ApplicationFactory $ appFactory ,
@@ -35,15 +38,32 @@ public function resetDocumentIdStack(): void
3538 {
3639 $ this ->output = null ;
3740 $ this ->returnCode = null ;
41+ $ this ->stream = null ;
42+ }
43+
44+ #[Given('the next command input is :string ' )]
45+ public function theNextCommandInputIs (string $ string )
46+ {
47+ if (null === $ this ->stream ) {
48+ $ this ->stream = fopen ('php://memory ' , 'r+ ' , false );
49+ }
50+ fwrite ($ this ->stream , $ string .\PHP_EOL );
3851 }
3952
4053 #[When('I run command :command ' )]
4154 public function iRunCommand (string $ command ): void
4255 {
4356 $ params = explode (' ' , $ command );
44- array_unshift ($ params , '-n ' );
57+ if (null === $ this ->stream ) {
58+ array_unshift ($ params , '-n ' );
59+ }
4560 array_unshift ($ params , 'console ' );
4661 $ input = new ArgvInput ($ params );
62+ if (null !== $ this ->stream ) {
63+ rewind ($ this ->stream );
64+ $ input ->setStream ($ this ->stream );
65+ $ input ->setInteractive (true );
66+ }
4767 $ output = new BufferedOutput ();
4868
4969 try {
0 commit comments