File tree 2 files changed +23
-4
lines changed
src/Symfony/Component/Console 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \Console \Application ;
15
15
use Symfony \Component \Console \Exception \RuntimeException ;
16
+ use Symfony \Component \Console \Exception \InvalidArgumentException ;
16
17
use Symfony \Component \Console \Formatter \OutputFormatter ;
17
18
use Symfony \Component \Console \Helper \Helper ;
18
19
use Symfony \Component \Console \Helper \ProgressBar ;
@@ -393,12 +394,16 @@ public function newLine($count = 1)
393
394
}
394
395
395
396
/**
397
+ * Sets the input stream used by the SymfonyQuestionHelper.
398
+ *
396
399
* @param resource $stream
400
+ *
401
+ * @throws InvalidArgumentException If the given stream is not a resource
397
402
*/
398
403
public function setInputStream ($ stream )
399
404
{
400
405
if (!is_resource ($ stream )) {
401
- throw new \ InvalidArgumentException (sprintf ('The stream must be a valid resource, %s given ' ) , gettype ($ stream ));
406
+ throw new InvalidArgumentException (sprintf ('Input stream must be a valid resource, %s given ' , gettype ($ stream) ));
402
407
}
403
408
404
409
$ this ->inputStream = $ stream ;
Original file line number Diff line number Diff line change @@ -80,15 +80,29 @@ public function testSetInputStream()
80
80
rewind ($ stream );
81
81
82
82
$ command ->setCode (function ($ input , $ output ) use ($ command , $ stream ) {
83
- $ io = new SymfonyStyle ($ input , $ output );
83
+ $ sfStyle = new SymfonyStyle ($ input , $ output );
84
84
85
- $ io ->setInputStream ($ stream );
86
- $ io ->ask ('What \'s your name? ' );
85
+ $ sfStyle ->setInputStream ($ stream );
86
+ $ sfStyle ->ask ('What \'s your name? ' );
87
87
});
88
88
89
89
$ this ->tester ->execute (array ());
90
90
$ this ->assertSame (0 , $ this ->tester ->getStatusCode ());
91
91
}
92
+
93
+ /**
94
+ * @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
95
+ * @expectedMessage Input stream must be a valid resource, string given
96
+ */
97
+ public function testSetInputStreamWithWrongResource ()
98
+ {
99
+ $ this ->command ->setCode (function ($ input , $ output ) {
100
+ $ sfStyle = new SymfonyStyle ($ input , $ output );
101
+ $ sfStyle ->setInputStream ('invalid type ' );
102
+ });
103
+
104
+ $ this ->tester ->execute (array ());
105
+ }
92
106
}
93
107
94
108
/**
You can’t perform that action at this time.
0 commit comments