@@ -155,13 +155,20 @@ public static function getTestingHandler(): TestingHttpHandler
155
155
}
156
156
157
157
/**
158
- * Check if Http is currently in testing mode.
158
+ * Convenience method to quickly mock a request in testing mode.
159
+ * Follows Laravel's Http::fake() pattern.
160
+ *
161
+ * @param string $method HTTP method to mock (default: '*' for any)
159
162
*
160
- * @return bool True if in testing mode, false otherwise
163
+ * @throws \RuntimeException If not in testing mode
161
164
*/
162
- public static function isTesting ( ): bool
165
+ public static function mock ( string $ method = ' * ' ): MockRequestBuilder
163
166
{
164
- return self ::$ isTesting ;
167
+ if (! self ::$ isTesting || self ::$ testingInstance === null ) {
168
+ throw new \RuntimeException ('Not in testing mode. Call Http::testing() first. ' );
169
+ }
170
+
171
+ return self ::$ testingInstance ->mock ($ method );
165
172
}
166
173
167
174
/**
@@ -202,73 +209,6 @@ public static function setInstance(HttpHandler $handler): void
202
209
}
203
210
}
204
211
205
- /**
206
- * Convenience method to quickly mock a request in testing mode.
207
- *
208
- * @param string $method HTTP method to mock (default: '*' for any)
209
- *
210
- * @throws \RuntimeException If not in testing mode
211
- */
212
- public static function mock (string $ method = '* ' ): MockRequestBuilder
213
- {
214
- if (! self ::$ isTesting || self ::$ testingInstance === null ) {
215
- throw new \RuntimeException ('Not in testing mode. Call Http::testing() first. ' );
216
- }
217
-
218
- return self ::$ testingInstance ->mock ($ method );
219
- }
220
-
221
- /**
222
- * Assert that a specific request was made during testing.
223
- *
224
- * @param string $method HTTP method
225
- * @param string $url URL pattern
226
- * @param array<string, mixed> $options Additional matching options
227
- *
228
- * @throws \RuntimeException If not in testing mode
229
- * @throws \Exception If assertion fails
230
- */
231
- public static function assertRequestMade (string $ method , string $ url , array $ options = []): void
232
- {
233
- if (! self ::$ isTesting || self ::$ testingInstance === null ) {
234
- throw new \RuntimeException ('Not in testing mode. Call Http::testing() first. ' );
235
- }
236
-
237
- self ::$ testingInstance ->assertRequestMade ($ method , $ url , $ options );
238
- }
239
-
240
- /**
241
- * Assert that no HTTP requests were made during testing.
242
- *
243
- * @throws \RuntimeException If not in testing mode
244
- * @throws \Exception If assertion fails
245
- */
246
- public static function assertNoRequestsMade (): void
247
- {
248
- if (! self ::$ isTesting || self ::$ testingInstance === null ) {
249
- throw new \RuntimeException ('Not in testing mode. Call Http::testing() first. ' );
250
- }
251
-
252
- self ::$ testingInstance ->assertNoRequestsMade ();
253
- }
254
-
255
- /**
256
- * Assert a specific number of requests were made during testing.
257
- *
258
- * @param int $expected Expected number of requests
259
- *
260
- * @throws \RuntimeException If not in testing mode
261
- * @throws \Exception If assertion fails
262
- */
263
- public static function assertRequestCount (int $ expected ): void
264
- {
265
- if (! self ::$ isTesting || self ::$ testingInstance === null ) {
266
- throw new \RuntimeException ('Not in testing mode. Call Http::testing() first. ' );
267
- }
268
-
269
- self ::$ testingInstance ->assertRequestCount ($ expected );
270
- }
271
-
272
212
/**
273
213
* Magic method to handle dynamic static calls.
274
214
*
@@ -298,6 +238,6 @@ public static function __callStatic(string $method, array $arguments)
298
238
return $ handler ->{$ method }(...$ arguments );
299
239
}
300
240
301
- throw new \BadMethodCallException ("Method {$ method } does not exist on " . static ::class);
241
+ throw new \BadMethodCallException ("Method {$ method } does not exist on " . static ::class);
302
242
}
303
243
}
0 commit comments