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