@@ -156,7 +156,7 @@ public function testPingAfterPreviousFactoryRejectsUnderlyingClientWillCreateNew
156156
157157 public function testPingAfterPreviousUnderlyingClientAlreadyClosedWillCreateNewUnderlyingConnection ()
158158 {
159- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
159+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
160160 $ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
161161
162162 $ this ->factory ->expects ($ this ->exactly (2 ))->method ('createClient ' )->willReturnOnConsecutiveCalls (
@@ -183,7 +183,7 @@ public function testPingAfterCloseWillRejectWithoutCreatingUnderlyingConnection(
183183 public function testPingAfterPingWillNotStartIdleTimerWhenFirstPingResolves ()
184184 {
185185 $ deferred = new Deferred ();
186- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
186+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
187187 $ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls (
188188 $ deferred ->promise (),
189189 new Promise (function () { })
@@ -201,7 +201,7 @@ public function testPingAfterPingWillNotStartIdleTimerWhenFirstPingResolves()
201201 public function testPingAfterPingWillStartAndCancelIdleTimerWhenSecondPingStartsAfterFirstResolves ()
202202 {
203203 $ deferred = new Deferred ();
204- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
204+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
205205 $ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls (
206206 $ deferred ->promise (),
207207 new Promise (function () { })
@@ -220,7 +220,7 @@ public function testPingAfterPingWillStartAndCancelIdleTimerWhenSecondPingStarts
220220
221221 public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWithoutCloseEvent ()
222222 {
223- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
223+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
224224 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
225225 $ client ->expects ($ this ->once ())->method ('close ' )->willReturn (\React \Promise \resolve ());
226226
@@ -298,7 +298,7 @@ public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlready
298298 public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved ()
299299 {
300300 $ deferred = new Deferred ();
301- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
301+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
302302 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
303303 $ client ->expects ($ this ->once ())->method ('close ' );
304304
@@ -316,7 +316,7 @@ public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved()
316316 public function testCloseAfterPingRejectsWillEmitClose ()
317317 {
318318 $ deferred = new Deferred ();
319- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
319+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
320320 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
321321 $ client ->expects ($ this ->once ())->method ('close ' )->willReturnCallback (function () use ($ client ) {
322322 $ client ->emit ('close ' );
@@ -358,7 +358,7 @@ public function testEndAfterPingWillEndUnderlyingClient()
358358
359359 public function testEndAfterPingWillCloseClientWhenUnderlyingClientEmitsClose ()
360360 {
361- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'end ' ))-> getMock ( );
361+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'end ' ));
362362 $ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
363363 $ client ->expects ($ this ->once ())->method ('end ' );
364364
@@ -378,7 +378,7 @@ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError()
378378 {
379379 $ error = new \RuntimeException ();
380380
381- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
381+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
382382 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
383383
384384 $ deferred = new Deferred ();
@@ -393,7 +393,7 @@ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError()
393393
394394 public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose ()
395395 {
396- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
396+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
397397 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
398398
399399 $ deferred = new Deferred ();
@@ -409,7 +409,7 @@ public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose()
409409 public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnectionEmitsCloseAfterPingIsAlreadyResolved ()
410410 {
411411 $ deferred = new Deferred ();
412- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
412+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
413413 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
414414
415415 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -428,7 +428,7 @@ public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnect
428428
429429 public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubChannel ()
430430 {
431- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
431+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
432432 $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
433433
434434 $ deferred = new Deferred ();
@@ -443,7 +443,7 @@ public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubCh
443443
444444 public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClosesWhileUsingPubSubChannel ()
445445 {
446- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
446+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
447447 $ client ->expects ($ this ->exactly (6 ))->method ('__call ' )->willReturn (\React \Promise \resolve ());
448448
449449 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -474,7 +474,7 @@ public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClo
474474 public function testSubscribeWillResolveWhenUnderlyingClientResolvesSubscribeAndNotStartIdleTimerWithIdleDueToSubscription ()
475475 {
476476 $ deferred = new Deferred ();
477- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
477+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
478478 $ client ->expects ($ this ->once ())->method ('__call ' )->with ('subscribe ' )->willReturn ($ deferred ->promise ());
479479
480480 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -492,7 +492,7 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso
492492 {
493493 $ deferredSubscribe = new Deferred ();
494494 $ deferredUnsubscribe = new Deferred ();
495- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
495+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
496496 $ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls ($ deferredSubscribe ->promise (), $ deferredUnsubscribe ->promise ());
497497
498498 $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -509,4 +509,15 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso
509509 $ deferredUnsubscribe ->resolve (array ('unsubscribe ' , 'foo ' , 0 ));
510510 $ promise ->then ($ this ->expectCallableOnceWith (array ('unsubscribe ' , 'foo ' , 0 )));
511511 }
512+
513+ public function createCallableMockWithOriginalConstructorDisabled ($ array )
514+ {
515+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'addMethods ' )) {
516+ // PHPUnit 9+
517+ return $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->onlyMethods ($ array )->getMock ();
518+ } else {
519+ // legacy PHPUnit 4 - PHPUnit 8
520+ return $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods ($ array )->getMock ();
521+ }
522+ }
512523}
0 commit comments