@@ -35,11 +35,21 @@ protected function setUpCompat()
35
35
*
36
36
* @test
37
37
*/
38
+ #[\PHPUnit \Framework \Attributes \Test]
38
39
public function testDelegateReturnsMockResult ()
39
40
{
40
- $ expected = 3 ;
41
- $ mock = $ this ->getMockForAbstractClass ($ this ->className );
42
-
41
+ $ expected = 3 ;
42
+ $ mockBuilder = $ this ->getMockBuilder ($ this ->className );
43
+
44
+ // `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
45
+ if (method_exists ($ mockBuilder , 'onlyMethods ' )) {
46
+ $ mockBuilder ->onlyMethods ([MockDelegateFunctionBuilder::METHOD ]);
47
+ } else {
48
+ $ mockBuilder ->setMethods ([MockDelegateFunctionBuilder::METHOD ]);
49
+ }
50
+
51
+ $ mock = $ mockBuilder ->getMock ();
52
+
43
53
$ mock ->expects ($ this ->once ())
44
54
->method (MockDelegateFunctionBuilder::METHOD )
45
55
->willReturn ($ expected );
@@ -53,14 +63,24 @@ public function testDelegateReturnsMockResult()
53
63
*
54
64
* @test
55
65
*/
66
+ #[\PHPUnit \Framework \Attributes \Test]
56
67
public function testDelegateForwardsArguments ()
57
68
{
58
- $ mock = $ this ->getMockForAbstractClass ($ this ->className );
59
-
69
+ $ mockBuilder = $ this ->getMockBuilder ($ this ->className );
70
+
71
+ // `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
72
+ if (method_exists ($ mockBuilder , 'onlyMethods ' )) {
73
+ $ mockBuilder ->onlyMethods ([MockDelegateFunctionBuilder::METHOD ]);
74
+ } else {
75
+ $ mockBuilder ->setMethods ([MockDelegateFunctionBuilder::METHOD ]);
76
+ }
77
+
78
+ $ mock = $ mockBuilder ->getMock ();
79
+
60
80
$ mock ->expects ($ this ->once ())
61
81
->method (MockDelegateFunctionBuilder::METHOD )
62
82
->with (1 , 2 );
63
-
83
+
64
84
call_user_func ($ mock ->getCallable (), 1 , 2 );
65
85
}
66
86
}
0 commit comments