@@ -235,23 +235,21 @@ public function testOpen()
235235 $ path = 'foo.bar ' ;
236236 $ filesystem = $ this ->mockAdapter ();
237237
238- $ stream = $ this -> getMock ( ' React\Filesystem\Stream\GenericStreamInterface ' , [], [ ' foo:bar ']) ;
238+ $ fd = ' foo:bar ' ;
239239 $ flags = 'abc ' ;
240240
241241 $ filesystem
242242 ->expects ($ this ->once ())
243243 ->method ('open ' )
244244 ->with ($ path , $ flags )
245- ->will ($ this ->returnValue (new FulfilledPromise ($ stream )))
245+ ->will ($ this ->returnValue (new FulfilledPromise ($ fd )))
246246 ;
247247
248- $ callbackFired = false ;
249- (new File ($ path , Filesystem::createFromAdapter ($ filesystem )))->open ($ flags )->then (function ($ passStream ) use (&$ callbackFired , $ stream ) {
250- $ this ->assertSame ($ stream , $ passStream );
251- $ callbackFired = true ;
252- });
248+ $ fs = Filesystem::createFromAdapter ($ filesystem );
249+ $ pass = $ this ->await ((new File ($ path , $ fs ))->open ($ flags ), $ fs ->getAdapter ()->getLoop ());
253250
254- $ this ->assertTrue ($ callbackFired );
251+ $ this ->assertInstanceOf ('\React\Filesystem\Stream\GenericStreamInterface ' , $ pass );
252+ $ this ->assertSame ($ fd , $ pass ->getFiledescriptor ());
255253 }
256254
257255
@@ -260,14 +258,14 @@ public function testOpenTwice()
260258 $ path = 'foo.bar ' ;
261259 $ filesystem = $ this ->mockAdapter ();
262260
263- $ stream = $ this -> getMock ( ' React\Filesystem\Stream\GenericStreamInterface ' , [], [ ' foo:bar ']) ;
261+ $ fd = ' foo:bar ' ;
264262 $ flags = 'abc ' ;
265263
266264 $ filesystem
267265 ->expects ($ this ->once ())
268266 ->method ('open ' )
269267 ->with ($ path , $ flags )
270- ->will ($ this ->returnValue (new FulfilledPromise ($ stream )))
268+ ->will ($ this ->returnValue (new FulfilledPromise ($ fd )))
271269 ;
272270
273271 $ file = new File ($ path , Filesystem::createFromAdapter ($ filesystem ));
@@ -280,14 +278,10 @@ public function testGetContents()
280278 $ path = 'foo.bar ' ;
281279 $ fd = '0123456789abcdef ' ;
282280
283- $ openPromise = $ this ->getMock ('React\Promise\PromiseInterface ' , [
284- 'then ' ,
285- ]);
286-
287281 $ filesystem = $ this ->mockAdapter ();
288282
289283 $ filesystem
290- ->expects ($ this ->once ())
284+ ->expects ($ this ->any ())
291285 ->method ('stat ' )
292286 ->with ($ path )
293287 ->will ($ this ->returnValue (new FulfilledPromise ([
@@ -299,14 +293,14 @@ public function testGetContents()
299293 ->expects ($ this ->once ())
300294 ->method ('open ' )
301295 ->with ($ path , 'r ' )
302- ->will ($ this ->returnValue ($ openPromise ))
296+ ->will ($ this ->returnValue (new FulfilledPromise ( $ fd ) ))
303297 ;
304298
305299 $ filesystem
306300 ->expects ($ this ->once ())
307301 ->method ('read ' )
308302 ->with ($ fd , 1 , 0 )
309- ->will ($ this ->returnValue (new FulfilledPromise (str_repeat ( 'a ' , 1 ) )))
303+ ->will ($ this ->returnValue (new FulfilledPromise ('a ' )))
310304 ;
311305
312306 $ filesystem
@@ -316,21 +310,6 @@ public function testGetContents()
316310 ->will ($ this ->returnValue (new FulfilledPromise ()))
317311 ;
318312
319- $ stream = new ReadableStream (
320- $ path ,
321- $ fd ,
322- $ filesystem
323- );
324-
325- $ openPromise
326- ->expects ($ this ->once ())
327- ->method ('then ' )
328- ->with ($ this ->isType ('callable ' ))
329- ->will ($ this ->returnCallback (function ($ resolveCb ) use ($ stream ) {
330- return new FulfilledPromise ($ resolveCb ($ stream ));
331- }))
332- ;
333-
334313 $ getContentsPromise = (new File ($ path , Filesystem::createFromAdapter ($ filesystem )))->getContents ();
335314 $ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ getContentsPromise );
336315 }
@@ -341,30 +320,20 @@ public function testClose()
341320 $ fd = '0123456789abcdef ' ;
342321 $ filesystem = $ this ->mockAdapter ();
343322
344- $ stream = $ this ->getMock ('React\Filesystem\Stream\GenericStreamInterface ' , [
345- 'getFiledescriptor ' ,
346- ], [
347- 'foo:bar ' ,
348- ]);
323+ $ openPromise = new FulfilledPromise ($ fd );
349324
350- $ stream
351- ->expects ($ this ->once ())
352- ->method ('getFiledescriptor ' )
353- ->with ()
354- ->will ($ this ->returnValue ($ fd ))
325+ $ filesystem
326+ ->method ('stat ' )
327+ ->with ($ path )
328+ ->will ($ this ->returnValue (new FulfilledPromise ([
329+ 'size ' => 1 ,
330+ ])))
355331 ;
356332
357- $ openPromise = $ this ->getMock ('React\Promise\PromiseInterface ' , [
358- 'then ' ,
359- ]);
360-
361- $ openPromise
362- ->expects ($ this ->once ())
363- ->method ('then ' )
364- ->with ($ this ->isType ('callable ' ))
365- ->will ($ this ->returnCallback (function ($ resolveCb ) use ($ stream ) {
366- return new FulfilledPromise ($ resolveCb ($ stream ));
367- }))
333+ $ filesystem
334+ ->method ('read ' )
335+ ->with ($ path )
336+ ->will ($ this ->returnValue (new FulfilledPromise ('a ' )))
368337 ;
369338
370339 $ filesystem
@@ -374,24 +343,11 @@ public function testClose()
374343 ->will ($ this ->returnValue ($ openPromise ))
375344 ;
376345
377- $ closePromise = $ this ->getMock ('React\Promise\PromiseInterface ' , [
378- 'then ' ,
379- ]);
380-
381- $ closePromise
382- ->expects ($ this ->once ())
383- ->method ('then ' )
384- ->with ($ this ->isType ('callable ' ))
385- ->will ($ this ->returnCallback (function ($ resolveCb ) use ($ stream ) {
386- return \React \Promise \resolve ($ resolveCb ($ stream ));
387- }))
388- ;
389-
390346 $ filesystem
391347 ->expects ($ this ->once ())
392348 ->method ('close ' )
393349 ->with ($ fd )
394- ->will ($ this ->returnValue ($ closePromise ))
350+ ->will ($ this ->returnValue (\ React \ Promise \resolve () ))
395351 ;
396352
397353 $ file = new File ($ path , Filesystem::createFromAdapter ($ filesystem ));
0 commit comments