@@ -60,6 +60,41 @@ public function __construct(InvocationHandler $handler, Matcher $matcher, Config
60
60
$ this ->configurableMethods = $ configurableMethods ;
61
61
}
62
62
63
+ /**
64
+ * @throws InvalidArgumentException
65
+ * @throws MethodCannotBeConfiguredException
66
+ * @throws MethodNameAlreadyConfiguredException
67
+ *
68
+ * @return $this
69
+ */
70
+ public function method (Constraint |PropertyHook |string $ constraint ): InvocationStubber
71
+ {
72
+ if ($ this ->matcher ->hasMethodNameRule ()) {
73
+ throw new MethodNameAlreadyConfiguredException ;
74
+ }
75
+
76
+ if ($ constraint instanceof PropertyHook) {
77
+ $ constraint = $ constraint ->asString ();
78
+ }
79
+
80
+ if (is_string ($ constraint )) {
81
+ $ this ->configurableMethodNames ??= array_flip (
82
+ array_map (
83
+ static fn (ConfigurableMethod $ configurable ) => strtolower ($ configurable ->name ()),
84
+ $ this ->configurableMethods ,
85
+ ),
86
+ );
87
+
88
+ if (!array_key_exists (strtolower ($ constraint ), $ this ->configurableMethodNames )) {
89
+ throw new MethodCannotBeConfiguredException ($ constraint );
90
+ }
91
+ }
92
+
93
+ $ this ->matcher ->setMethodNameRule (new Rule \MethodName ($ constraint ));
94
+
95
+ return $ this ;
96
+ }
97
+
63
98
/**
64
99
* @throws MatcherAlreadyRegisteredException
65
100
*
@@ -72,6 +107,47 @@ public function id(string $id): InvocationStubber
72
107
return $ this ;
73
108
}
74
109
110
+ /**
111
+ * @return $this
112
+ */
113
+ public function after (string $ id ): InvocationStubber
114
+ {
115
+ $ this ->matcher ->setAfterMatchBuilderId ($ id );
116
+
117
+ return $ this ;
118
+ }
119
+
120
+ /**
121
+ * @throws \PHPUnit\Framework\Exception
122
+ * @throws MethodNameNotConfiguredException
123
+ * @throws MethodParametersAlreadyConfiguredException
124
+ *
125
+ * @return $this
126
+ */
127
+ public function with (mixed ...$ arguments ): InvocationStubber
128
+ {
129
+ $ this ->ensureParametersCanBeConfigured ();
130
+
131
+ $ this ->matcher ->setParametersRule (new Rule \Parameters ($ arguments ));
132
+
133
+ return $ this ;
134
+ }
135
+
136
+ /**
137
+ * @throws MethodNameNotConfiguredException
138
+ * @throws MethodParametersAlreadyConfiguredException
139
+ *
140
+ * @return $this
141
+ */
142
+ public function withAnyParameters (): InvocationStubber
143
+ {
144
+ $ this ->ensureParametersCanBeConfigured ();
145
+
146
+ $ this ->matcher ->setParametersRule (new Rule \AnyParameters );
147
+
148
+ return $ this ;
149
+ }
150
+
75
151
/**
76
152
* @return $this
77
153
*/
@@ -191,82 +267,6 @@ public function willThrowException(Throwable $exception): InvocationStubber
191
267
return $ this ->will ($ stub );
192
268
}
193
269
194
- /**
195
- * @return $this
196
- */
197
- public function after (string $ id ): InvocationStubber
198
- {
199
- $ this ->matcher ->setAfterMatchBuilderId ($ id );
200
-
201
- return $ this ;
202
- }
203
-
204
- /**
205
- * @throws \PHPUnit\Framework\Exception
206
- * @throws MethodNameNotConfiguredException
207
- * @throws MethodParametersAlreadyConfiguredException
208
- *
209
- * @return $this
210
- */
211
- public function with (mixed ...$ arguments ): InvocationStubber
212
- {
213
- $ this ->ensureParametersCanBeConfigured ();
214
-
215
- $ this ->matcher ->setParametersRule (new Rule \Parameters ($ arguments ));
216
-
217
- return $ this ;
218
- }
219
-
220
- /**
221
- * @throws MethodNameNotConfiguredException
222
- * @throws MethodParametersAlreadyConfiguredException
223
- *
224
- * @return $this
225
- */
226
- public function withAnyParameters (): InvocationStubber
227
- {
228
- $ this ->ensureParametersCanBeConfigured ();
229
-
230
- $ this ->matcher ->setParametersRule (new Rule \AnyParameters );
231
-
232
- return $ this ;
233
- }
234
-
235
- /**
236
- * @throws InvalidArgumentException
237
- * @throws MethodCannotBeConfiguredException
238
- * @throws MethodNameAlreadyConfiguredException
239
- *
240
- * @return $this
241
- */
242
- public function method (Constraint |PropertyHook |string $ constraint ): InvocationStubber
243
- {
244
- if ($ this ->matcher ->hasMethodNameRule ()) {
245
- throw new MethodNameAlreadyConfiguredException ;
246
- }
247
-
248
- if ($ constraint instanceof PropertyHook) {
249
- $ constraint = $ constraint ->asString ();
250
- }
251
-
252
- if (is_string ($ constraint )) {
253
- $ this ->configurableMethodNames ??= array_flip (
254
- array_map (
255
- static fn (ConfigurableMethod $ configurable ) => strtolower ($ configurable ->name ()),
256
- $ this ->configurableMethods ,
257
- ),
258
- );
259
-
260
- if (!array_key_exists (strtolower ($ constraint ), $ this ->configurableMethodNames )) {
261
- throw new MethodCannotBeConfiguredException ($ constraint );
262
- }
263
- }
264
-
265
- $ this ->matcher ->setMethodNameRule (new Rule \MethodName ($ constraint ));
266
-
267
- return $ this ;
268
- }
269
-
270
270
/**
271
271
* @throws MethodNameNotConfiguredException
272
272
* @throws MethodParametersAlreadyConfiguredException
0 commit comments