@@ -444,4 +444,43 @@ public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClo
444444 $ this ->client ->on ('punsubscribe ' , $ this ->expectCallableOnce ());
445445 $ client ->emit ('close ' );
446446 }
447+
448+ public function testSubscribeWillResolveWhenUnderlyingClientResolvesSubscribeAndNotStartIdleTimerWithIdleDueToSubscription ()
449+ {
450+ $ deferred = new Deferred ();
451+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
452+ $ client ->expects ($ this ->once ())->method ('__call ' )->with ('subscribe ' )->willReturn ($ deferred ->promise ());
453+
454+ $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
455+
456+ $ this ->loop ->expects ($ this ->never ())->method ('addTimer ' );
457+
458+ $ promise = $ this ->client ->subscribe ('foo ' );
459+ $ client ->emit ('subscribe ' , array ('foo ' , 1 ));
460+ $ deferred ->resolve (array ('subscribe ' , 'foo ' , 1 ));
461+
462+ $ promise ->then ($ this ->expectCallableOnceWith (array ('subscribe ' , 'foo ' , 1 )));
463+ }
464+
465+ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientResolvesUnsubscribeAndStartIdleTimerWhenSubscriptionStopped ()
466+ {
467+ $ deferredSubscribe = new Deferred ();
468+ $ deferredUnsubscribe = new Deferred ();
469+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' ))->getMock ();
470+ $ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls ($ deferredSubscribe ->promise (), $ deferredUnsubscribe ->promise ());
471+
472+ $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
473+
474+ $ this ->loop ->expects ($ this ->once ())->method ('addTimer ' );
475+
476+ $ promise = $ this ->client ->subscribe ('foo ' );
477+ $ client ->emit ('subscribe ' , array ('foo ' , 1 ));
478+ $ deferredSubscribe ->resolve (array ('subscribe ' , 'foo ' , 1 ));
479+ $ promise ->then ($ this ->expectCallableOnceWith (array ('subscribe ' , 'foo ' , 1 )));
480+
481+ $ promise = $ this ->client ->unsubscribe ('foo ' );
482+ $ client ->emit ('unsubscribe ' , array ('foo ' , 0 ));
483+ $ deferredUnsubscribe ->resolve (array ('unsubscribe ' , 'foo ' , 0 ));
484+ $ promise ->then ($ this ->expectCallableOnceWith (array ('unsubscribe ' , 'foo ' , 0 )));
485+ }
447486}
0 commit comments