6
6
7
7
/**
8
8
* @method static \GuzzleHttp\Promise\PromiseInterface response($body = null, $status = 200, $headers = [])
9
- * @method static \Illuminate\Http\Client\Factory fake($callback = null)
10
9
* @method static \Illuminate\Http\Client\PendingRequest accept(string $contentType)
11
10
* @method static \Illuminate\Http\Client\PendingRequest acceptJson()
12
11
* @method static \Illuminate\Http\Client\PendingRequest asForm()
43
42
* @method static \Illuminate\Http\Client\Response post(string $url, array $data = [])
44
43
* @method static \Illuminate\Http\Client\Response put(string $url, array $data = [])
45
44
* @method static \Illuminate\Http\Client\Response send(string $method, string $url, array $options = [])
46
- * @method static \Illuminate\Http\Client\ResponseSequence fakeSequence(string $urlPattern = '*')
47
45
* @method static void assertSent(callable $callback)
48
46
* @method static void assertSentInOrder(array $callbacks)
49
47
* @method static void assertNotSent(callable $callback)
@@ -64,4 +62,46 @@ protected static function getFacadeAccessor()
64
62
{
65
63
return Factory::class;
66
64
}
65
+
66
+ /**
67
+ * Register a stub callable that will intercept requests and be able to return stub responses.
68
+ *
69
+ * @param \Closure|array $callback
70
+ * @return \Illuminate\Http\Client\Factory
71
+ */
72
+ public static function fake ($ callback = null )
73
+ {
74
+ return tap (static ::getFacadeRoot (), function ($ fake ) use ($ callback ) {
75
+ static ::swap ($ fake ->fake ($ callback ));
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Register a response sequence for the given URL pattern.
81
+ *
82
+ * @param string $urlPattern
83
+ * @return \Illuminate\Http\Client\ResponseSequence
84
+ */
85
+ public static function fakeSequence (string $ urlPattern = '* ' )
86
+ {
87
+ $ fake = tap (static ::getFacadeRoot (), function ($ fake ) {
88
+ static ::swap ($ fake );
89
+ });
90
+
91
+ return $ fake ->fakeSequence ($ urlPattern );
92
+ }
93
+
94
+ /**
95
+ * Stub the given URL using the given callback.
96
+ *
97
+ * @param string $url
98
+ * @param \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface|callable $callback
99
+ * @return \Illuminate\Http\Client\Factory
100
+ */
101
+ public static function stubUrl ($ url , $ callback )
102
+ {
103
+ return tap (static ::getFacadeRoot (), function ($ fake ) use ($ url , $ callback ) {
104
+ static ::swap ($ fake ->stubUrl ($ url , $ callback ));
105
+ });
106
+ }
67
107
}
0 commit comments