File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed
Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 44
55use Evenement \EventEmitter ;
66use React \EventLoop \LoopInterface ;
7+ use InvalidArgumentException ;
78
89class Stream extends EventEmitter implements DuplexStreamInterface
910{
@@ -18,6 +19,12 @@ class Stream extends EventEmitter implements DuplexStreamInterface
1819 public function __construct ($ stream , LoopInterface $ loop )
1920 {
2021 $ this ->stream = $ stream ;
22+ if (!is_resource ($ this ->stream ) || get_resource_type ($ this ->stream ) !== "stream " ) {
23+ throw new InvalidArgumentException ('First parameter must be a valid stream resource ' );
24+ }
25+
26+ stream_set_blocking ($ this ->stream , 0 );
27+
2128 $ this ->loop = $ loop ;
2229 $ this ->buffer = new Buffer ($ this ->stream , $ this ->loop );
2330
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ public function testConstructor()
1717 $ conn = new Stream ($ stream , $ loop );
1818 }
1919
20+ /**
21+ * @covers React\Stream\Stream::__construct
22+ */
23+ public function testConstructorThrowsExceptionOnInvalidStream ()
24+ {
25+ $ this ->setExpectedException ('InvalidArgumentException ' );
26+ $ loop = $ this ->createLoopMock ();
27+ $ conn = new Stream ('breakme ' , $ loop );
28+ }
29+
2030 /**
2131 * @covers React\Stream\Stream::__construct
2232 * @covers React\Stream\Stream::handleData
@@ -55,19 +65,6 @@ public function testWrite()
5565 $ this ->assertSame ("foo \n" , fgets ($ stream ));
5666 }
5767
58- /**
59- * @covers React\Stream\Stream::write
60- */
61- public function testWriteError ()
62- {
63- $ stream = "Silly developer, you can't write to to a string! " ;
64- $ loop = $ this ->createWriteableLoopMock ();
65-
66- $ conn = new Stream ($ stream , $ loop );
67- $ conn ->on ('error ' , $ this ->expectCallableOnce ());
68- $ conn ->write ('Attempting to write to a string ' );
69- }
70-
7168 /**
7269 * @covers React\Stream\Stream::end
7370 */
You can’t perform that action at this time.
0 commit comments