@@ -52,19 +52,29 @@ protected function expectCallableOnceWithException($class, $message, $code)
52
52
*/
53
53
protected function createCallableMock ()
54
54
{
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
+ }
56
62
}
57
63
58
- public function setExpectedException ($ exception , $ message = '' , $ code = 0 )
64
+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
59
65
{
60
66
if (method_exists ($ this , 'expectException ' )) {
67
+ // PHPUnit 5.2+
61
68
$ 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 );
64
74
}
65
- $ this ->expectExceptionCode ($ code );
66
75
} else {
67
- parent ::setExpectedException ($ exception , $ message , $ code );
76
+ // legacy PHPUnit 4 - PHPUnit 5.1
77
+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
68
78
}
69
79
}
70
80
0 commit comments