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