77use React \Filesystem \Node \Directory ;
88use React \Filesystem \Node \File ;
99use React \Filesystem \ObjectStream ;
10+ use React \Filesystem \Stream \ReadableStream ;
1011use React \Promise \Deferred ;
1112use React \Promise \FulfilledPromise ;
1213use React \Promise \RejectedPromise ;
@@ -296,27 +297,48 @@ public function testGetContents()
296297 {
297298 $ path = 'foo.bar ' ;
298299 $ fd = '0123456789abcdef ' ;
299- $ filesystem = $ this ->mockAdapter ();
300300
301- $ stream = $ this ->getMock ('React\Filesystem\Stream\ReadableStream ' , [
302- 'getFiledescriptor ' ,
303- 'resume ' ,
304- ], [
305- 'foo:bar ' ,
306- $ fd ,
307- $ filesystem ,
301+ $ openPromise = $ this ->getMock ('React\Promise\PromiseInterface ' , [
302+ 'then ' ,
308303 ]);
309304
310- $ stream
305+ $ filesystem = $ this ->mockAdapter ();
306+
307+ $ filesystem
311308 ->expects ($ this ->once ())
312- ->method ('getFiledescriptor ' )
313- ->with ()
314- ->will ($ this ->returnValue ($ fd ))
309+ ->method ('stat ' )
310+ ->with ($ path )
311+ ->will ($ this ->returnValue (new FulfilledPromise ([
312+ 'size ' => 1 ,
313+ ])))
315314 ;
316315
317- $ openPromise = $ this ->getMock ('React\Promise\PromiseInterface ' , [
318- 'then ' ,
319- ]);
316+ $ filesystem
317+ ->expects ($ this ->once ())
318+ ->method ('open ' )
319+ ->with ($ path , 'r ' )
320+ ->will ($ this ->returnValue ($ openPromise ))
321+ ;
322+
323+ $ filesystem
324+ ->expects ($ this ->once ())
325+ ->method ('read ' )
326+ ->with ($ fd , 1 , 0 )
327+ ->will ($ this ->returnValue (new FulfilledPromise (str_repeat ('a ' , 1 ))))
328+ ;
329+
330+ $ filesystem
331+ ->expects ($ this ->once ())
332+ ->method ('close ' )
333+ ->with ($ fd )
334+ ->will ($ this ->returnValue (new FulfilledPromise ()))
335+ ;
336+
337+ $ stream = new ReadableStream (
338+ $ path ,
339+ $ fd ,
340+ $ filesystem
341+ );
320342
321343 $ openPromise
322344 ->expects ($ this ->once ())
@@ -327,13 +349,6 @@ public function testGetContents()
327349 }))
328350 ;
329351
330- $ filesystem
331- ->expects ($ this ->once ())
332- ->method ('open ' )
333- ->with ($ path , 'r ' )
334- ->will ($ this ->returnValue ($ openPromise ))
335- ;
336-
337352 $ getContentsPromise = (new File ($ path , Filesystem::createFromAdapter ($ filesystem )))->getContents ();
338353 $ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ getContentsPromise );
339354 }
0 commit comments