File tree 2 files changed +36
-0
lines changed
src/Symfony/Component/Console 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class SymfonyStyle extends OutputStyle
40
40
private $ progressBar ;
41
41
private $ lineLength ;
42
42
private $ bufferedOutput ;
43
+ private $ inputStream ;
43
44
44
45
/**
45
46
* @param InputInterface $input
@@ -348,6 +349,10 @@ public function askQuestion(Question $question)
348
349
349
350
if (!$ this ->questionHelper ) {
350
351
$ this ->questionHelper = new SymfonyQuestionHelper ();
352
+
353
+ if ($ this ->inputStream ) {
354
+ $ this ->questionHelper ->setInputStream ($ this ->inputStream );
355
+ }
351
356
}
352
357
353
358
$ answer = $ this ->questionHelper ->ask ($ this ->input , $ this , $ question );
@@ -387,6 +392,18 @@ public function newLine($count = 1)
387
392
$ this ->bufferedOutput ->write (str_repeat ("\n" , $ count ));
388
393
}
389
394
395
+ /**
396
+ * @param resource $stream
397
+ */
398
+ public function setInputStream ($ stream )
399
+ {
400
+ if (!is_resource ($ stream )) {
401
+ throw new \InvalidArgumentException (sprintf ('The stream must be a valid resource, %s given ' ), gettype ($ stream ));
402
+ }
403
+
404
+ $ this ->inputStream = $ stream ;
405
+ }
406
+
390
407
/**
391
408
* @return ProgressBar
392
409
*/
Original file line number Diff line number Diff line change @@ -70,6 +70,25 @@ public function testLongWordsBlockWrapping()
70
70
$ expectedCount = (int ) ceil ($ wordLength / ($ maxLineLength )) + (int ) ($ wordLength > $ maxLineLength - 5 );
71
71
$ this ->assertSame ($ expectedCount , substr_count ($ this ->tester ->getDisplay (true ), ' § ' ));
72
72
}
73
+
74
+ public function testSetInputStream ()
75
+ {
76
+ $ command = $ this ->command ;
77
+
78
+ $ stream = fopen ('php://memory ' , 'r+ ' , false );
79
+ fputs ($ stream , 'FooBar ' );
80
+ rewind ($ stream );
81
+
82
+ $ command ->setCode (function ($ input , $ output ) use ($ command , $ stream ) {
83
+ $ io = new SymfonyStyle ($ input , $ output );
84
+
85
+ $ io ->setInputStream ($ stream );
86
+ $ io ->ask ('What \'s your name? ' );
87
+ });
88
+
89
+ $ this ->tester ->execute (array ());
90
+ $ this ->assertSame (0 , $ this ->tester ->getStatusCode ());
91
+ }
73
92
}
74
93
75
94
/**
You can’t perform that action at this time.
0 commit comments