File tree Expand file tree Collapse file tree 4 files changed +38
-21
lines changed
Expand file tree Collapse file tree 4 files changed +38
-21
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,13 @@ public function close()
131131 $ this ->writable = false ;
132132
133133 $ this ->emit ('close ' );
134- $ this ->loop -> removeStream ( $ this -> stream );
134+ $ this ->pause ( );
135135 $ this ->buffer ->close ();
136136 $ this ->removeAllListeners ();
137137
138- $ this ->handleClose ();
138+ if (is_resource ($ this ->stream )) {
139+ fclose ($ this ->stream );
140+ }
139141 }
140142
141143 public function end ($ data = null )
@@ -191,14 +193,6 @@ public function handleData($stream)
191193 }
192194 }
193195
194- /** @internal */
195- public function handleClose ()
196- {
197- if (is_resource ($ this ->stream )) {
198- fclose ($ this ->stream );
199- }
200- }
201-
202196 /**
203197 * Returns whether this is a pipe resource in a legacy environment
204198 *
Original file line number Diff line number Diff line change @@ -105,10 +105,12 @@ public function close()
105105 $ this ->closed = true ;
106106
107107 $ this ->emit ('close ' );
108- $ this ->loop -> removeStream ( $ this -> stream );
108+ $ this ->pause ( );
109109 $ this ->removeAllListeners ();
110110
111- $ this ->handleClose ();
111+ if (is_resource ($ this ->stream )) {
112+ fclose ($ this ->stream );
113+ }
112114 }
113115
114116 /** @internal */
@@ -144,14 +146,6 @@ public function handleData()
144146 }
145147 }
146148
147- /** @internal */
148- public function handleClose ()
149- {
150- if (is_resource ($ this ->stream )) {
151- fclose ($ this ->stream );
152- }
153- }
154-
155149 /**
156150 * Returns whether this is a pipe resource in a legacy environment
157151 *
Original file line number Diff line number Diff line change @@ -242,12 +242,27 @@ public function testEndRemovesReadStreamFromLoop()
242242 {
243243 $ stream = fopen ('php://temp ' , 'r+ ' );
244244 $ loop = $ this ->createLoopMock ();
245- $ loop ->expects ($ this ->once ())->method ('removeReadStream ' );
245+ $ loop ->expects ($ this ->once ())->method ('addReadStream ' )->with ($ stream );
246+ $ loop ->expects ($ this ->once ())->method ('removeReadStream ' )->with ($ stream );
246247
247248 $ conn = new DuplexResourceStream ($ stream , $ loop );
248249 $ conn ->end ('bye ' );
249250 }
250251
252+ /**
253+ * @covers React\Stream\DuplexResourceStream::close
254+ */
255+ public function testCloseRemovesReadStreamFromLoop ()
256+ {
257+ $ stream = fopen ('php://temp ' , 'r+ ' );
258+ $ loop = $ this ->createLoopMock ();
259+ $ loop ->expects ($ this ->once ())->method ('addReadStream ' )->with ($ stream );
260+ $ loop ->expects ($ this ->once ())->method ('removeReadStream ' )->with ($ stream );
261+
262+ $ conn = new DuplexResourceStream ($ stream , $ loop );
263+ $ conn ->close ();
264+ }
265+
251266 public function testEndedStreamsShouldNotWrite ()
252267 {
253268 $ file = tempnam (sys_get_temp_dir (), 'reactphptest_ ' );
Original file line number Diff line number Diff line change @@ -204,6 +204,20 @@ public function testClosingStreamInDataEventShouldNotTriggerError()
204204 $ conn ->handleData ($ stream );
205205 }
206206
207+ /**
208+ * @covers React\Stream\ReadableResourceStream::close
209+ */
210+ public function testCloseRemovesReadStreamFromLoop ()
211+ {
212+ $ stream = fopen ('php://temp ' , 'r+ ' );
213+ $ loop = $ this ->createLoopMock ();
214+ $ loop ->expects ($ this ->once ())->method ('addReadStream ' )->with ($ stream );
215+ $ loop ->expects ($ this ->once ())->method ('removeReadStream ' )->with ($ stream );
216+
217+ $ conn = new ReadableResourceStream ($ stream , $ loop );
218+ $ conn ->close ();
219+ }
220+
207221 /**
208222 * @covers React\Stream\ReadableResourceStream::handleData
209223 */
You can’t perform that action at this time.
0 commit comments