@@ -53,22 +53,14 @@ public function getDouble(
5353 $ mockBuilder ->setConstructorArgs ($ constructorParams );
5454 }
5555
56- $ methods = [];
57- $ onConsecutiveCalls = [];
58- $ otherCalls = [];
56+ [$ onConsecutiveCalls , $ otherCalls , $ methods ] = $ this ->processParams ($ params );
5957
60- foreach ($ params as $ key => $ val ) {
61- if (is_int ($ key )) {
62- $ onConsecutiveCalls = array_merge ($ onConsecutiveCalls , $ val );
63- $ methods [] = array_keys ($ val )[0 ];
64- } else {
65- $ otherCalls [$ key ] = $ val ;
66- $ methods [] = $ key ;
67- }
58+ if ($ methods === []) {
59+ $ mock = $ mockBuilder ->getMock ();
60+ } else {
61+ $ mock = $ mockBuilder ->onlyMethods ($ methods )->getMock ();
6862 }
6963
70- $ mock = $ mockBuilder ->onlyMethods ($ methods )->getMock ();
71-
7264 foreach ($ onConsecutiveCalls as $ method => $ returns ) {
7365 $ mock ->expects ($ this ->any ())->method ($ method )
7466 ->will (
@@ -99,6 +91,30 @@ public function getDouble(
9991 return $ mock ;
10092 }
10193
94+ /**
95+ * @param array<string, mixed>|array<array> $params [method_name => return_value]
96+ *
97+ * @return array{0: array<string, array<string>>, 1: array<string, mixed>, 2: string[]}
98+ */
99+ private function processParams (array $ params ): array
100+ {
101+ $ onConsecutiveCalls = [];
102+ $ otherCalls = [];
103+ $ methods = [];
104+
105+ foreach ($ params as $ key => $ val ) {
106+ if (is_int ($ key )) {
107+ $ onConsecutiveCalls = array_merge ($ onConsecutiveCalls , $ val );
108+ $ methods [] = array_keys ($ val )[0 ];
109+ } else {
110+ $ otherCalls [$ key ] = $ val ;
111+ $ methods [] = $ key ;
112+ }
113+ }
114+
115+ return [$ onConsecutiveCalls , $ otherCalls , $ methods ];
116+ }
117+
102118 /**
103119 * @param array<mixed>|null $params
104120 * @param mixed $expects
0 commit comments