@@ -52,19 +52,29 @@ protected function expectCallableOnceWithException($class, $message, $code)
5252 */
5353 protected function createCallableMock ()
5454 {
55- return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
55+ if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'addMethods ' )) {
56+ // PHPUnit 8.5+
57+ return $ this ->getMockBuilder ('stdClass ' )->addMethods (array ('__invoke ' ))->getMock ();
58+ } else {
59+ // legacy PHPUnit 4 - PHPUnit 8.4
60+ return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
61+ }
5662 }
5763
58- public function setExpectedException ($ exception , $ message = '' , $ code = 0 )
64+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
5965 {
6066 if (method_exists ($ this , 'expectException ' )) {
67+ // PHPUnit 5.2+
6168 $ this ->expectException ($ exception );
62- if ($ message !== '' ) {
63- $ this ->expectExceptionMessage ($ message );
69+ if ($ exceptionMessage !== '' ) {
70+ $ this ->expectExceptionMessage ($ exceptionMessage );
71+ }
72+ if ($ exceptionCode !== null ) {
73+ $ this ->expectExceptionCode ($ exceptionCode );
6474 }
65- $ this ->expectExceptionCode ($ code );
6675 } else {
67- parent ::setExpectedException ($ exception , $ message , $ code );
76+ // legacy PHPUnit 4 - PHPUnit 5.1
77+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
6878 }
6979 }
7080
0 commit comments