@@ -156,7 +156,7 @@ public function testPingAfterPreviousFactoryRejectsUnderlyingClientWillCreateNew
156
156
157
157
public function testPingAfterPreviousUnderlyingClientAlreadyClosedWillCreateNewUnderlyingConnection ()
158
158
{
159
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
159
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
160
160
$ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
161
161
162
162
$ this ->factory ->expects ($ this ->exactly (2 ))->method ('createClient ' )->willReturnOnConsecutiveCalls (
@@ -183,7 +183,7 @@ public function testPingAfterCloseWillRejectWithoutCreatingUnderlyingConnection(
183
183
public function testPingAfterPingWillNotStartIdleTimerWhenFirstPingResolves ()
184
184
{
185
185
$ deferred = new Deferred ();
186
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
186
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
187
187
$ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls (
188
188
$ deferred ->promise (),
189
189
new Promise (function () { })
@@ -201,7 +201,7 @@ public function testPingAfterPingWillNotStartIdleTimerWhenFirstPingResolves()
201
201
public function testPingAfterPingWillStartAndCancelIdleTimerWhenSecondPingStartsAfterFirstResolves ()
202
202
{
203
203
$ deferred = new Deferred ();
204
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
204
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
205
205
$ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls (
206
206
$ deferred ->promise (),
207
207
new Promise (function () { })
@@ -220,7 +220,7 @@ public function testPingAfterPingWillStartAndCancelIdleTimerWhenSecondPingStarts
220
220
221
221
public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWithoutCloseEvent ()
222
222
{
223
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
223
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
224
224
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
225
225
$ client ->expects ($ this ->once ())->method ('close ' )->willReturn (\React \Promise \resolve ());
226
226
@@ -298,7 +298,7 @@ public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlready
298
298
public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved ()
299
299
{
300
300
$ deferred = new Deferred ();
301
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
301
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
302
302
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
303
303
$ client ->expects ($ this ->once ())->method ('close ' );
304
304
@@ -316,7 +316,7 @@ public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved()
316
316
public function testCloseAfterPingRejectsWillEmitClose ()
317
317
{
318
318
$ deferred = new Deferred ();
319
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'close ' ))-> getMock ( );
319
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'close ' ));
320
320
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
321
321
$ client ->expects ($ this ->once ())->method ('close ' )->willReturnCallback (function () use ($ client ) {
322
322
$ client ->emit ('close ' );
@@ -358,7 +358,7 @@ public function testEndAfterPingWillEndUnderlyingClient()
358
358
359
359
public function testEndAfterPingWillCloseClientWhenUnderlyingClientEmitsClose ()
360
360
{
361
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' , 'end ' ))-> getMock ( );
361
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' , 'end ' ));
362
362
$ client ->expects ($ this ->once ())->method ('__call ' )->with ('ping ' )->willReturn (\React \Promise \resolve ('PONG ' ));
363
363
$ client ->expects ($ this ->once ())->method ('end ' );
364
364
@@ -378,7 +378,7 @@ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError()
378
378
{
379
379
$ error = new \RuntimeException ();
380
380
381
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
381
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
382
382
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
383
383
384
384
$ deferred = new Deferred ();
@@ -393,7 +393,7 @@ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError()
393
393
394
394
public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose ()
395
395
{
396
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
396
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
397
397
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
398
398
399
399
$ deferred = new Deferred ();
@@ -409,7 +409,7 @@ public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose()
409
409
public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnectionEmitsCloseAfterPingIsAlreadyResolved ()
410
410
{
411
411
$ deferred = new Deferred ();
412
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
412
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
413
413
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
414
414
415
415
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -428,7 +428,7 @@ public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnect
428
428
429
429
public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubChannel ()
430
430
{
431
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
431
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
432
432
$ client ->expects ($ this ->once ())->method ('__call ' )->willReturn (\React \Promise \resolve ());
433
433
434
434
$ deferred = new Deferred ();
@@ -443,7 +443,7 @@ public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubCh
443
443
444
444
public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClosesWhileUsingPubSubChannel ()
445
445
{
446
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
446
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
447
447
$ client ->expects ($ this ->exactly (6 ))->method ('__call ' )->willReturn (\React \Promise \resolve ());
448
448
449
449
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -474,7 +474,7 @@ public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClo
474
474
public function testSubscribeWillResolveWhenUnderlyingClientResolvesSubscribeAndNotStartIdleTimerWithIdleDueToSubscription ()
475
475
{
476
476
$ deferred = new Deferred ();
477
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
477
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
478
478
$ client ->expects ($ this ->once ())->method ('__call ' )->with ('subscribe ' )->willReturn ($ deferred ->promise ());
479
479
480
480
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -492,7 +492,7 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso
492
492
{
493
493
$ deferredSubscribe = new Deferred ();
494
494
$ deferredUnsubscribe = new Deferred ();
495
- $ client = $ this ->getMockBuilder ( ' Clue\React\Redis\StreamingClient ' )-> disableOriginalConstructor ()-> setMethods ( array ('__call ' ))-> getMock ( );
495
+ $ client = $ this ->createCallableMockWithOriginalConstructorDisabled ( array ('__call ' ));
496
496
$ client ->expects ($ this ->exactly (2 ))->method ('__call ' )->willReturnOnConsecutiveCalls ($ deferredSubscribe ->promise (), $ deferredUnsubscribe ->promise ());
497
497
498
498
$ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
@@ -509,4 +509,15 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso
509
509
$ deferredUnsubscribe ->resolve (array ('unsubscribe ' , 'foo ' , 0 ));
510
510
$ promise ->then ($ this ->expectCallableOnceWith (array ('unsubscribe ' , 'foo ' , 0 )));
511
511
}
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
+ }
512
523
}
0 commit comments