@@ -53,7 +53,13 @@ protected function expectCallableOnceValue($type)
5353 */
5454 protected function createCallableMock ()
5555 {
56- return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
56+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'addMethods ' )) {
57+ // PHPUnit 9+
58+ return $ this ->getMockBuilder ('stdClass ' )->addMethods (array ('__invoke ' ))->getMock ();
59+ } else {
60+ // legacy PHPUnit 4 - PHPUnit 8
61+ return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
62+ }
5763 }
5864
5965 protected function createConnectionManagerMock ($ ret )
@@ -86,16 +92,20 @@ protected function assertPromiseReject($promise)
8692 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
8793 }
8894
89- public function setExpectedException ($ exception , $ message = '' , $ code = 0 )
95+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
9096 {
9197 if (method_exists ($ this , 'expectException ' )) {
98+ // PHPUnit 5+
9299 $ this ->expectException ($ exception );
93- if ($ message !== '' ) {
94- $ this ->expectExceptionMessage ($ message );
100+ if ($ exceptionMessage !== '' ) {
101+ $ this ->expectExceptionMessage ($ exceptionMessage );
102+ }
103+ if ($ exceptionCode !== null ) {
104+ $ this ->expectExceptionCode ($ exceptionCode );
95105 }
96- $ this ->expectExceptionCode ($ code );
97106 } else {
98- parent ::setExpectedException ($ exception , $ message , $ code );
107+ // legacy PHPUnit 4
108+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
99109 }
100110 }
101111}
0 commit comments