File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
tests/Unit/Request/Traits Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ abstract class Request implements ArrayAccess
81
81
*/
82
82
public $ client ;
83
83
84
+ /**
85
+ * @var \AlibabaCloud\Client\Clients\Client
86
+ */
87
+ public $ httpClient ;
88
+
84
89
/**
85
90
* @var Uri
86
91
*/
@@ -286,6 +291,19 @@ public function client($clientName)
286
291
return $ this ;
287
292
}
288
293
294
+
295
+ /**
296
+ *
297
+ *
298
+ * @param \AlibabaCloud\Client\Clients\Client $client
299
+ * @return $this
300
+ */
301
+ public function withHttpClient (\AlibabaCloud \Client \Clients \Client $ client )
302
+ {
303
+ $ this ->httpClient = $ client ;
304
+ return $ this ;
305
+ }
306
+
289
307
/**
290
308
* @return bool
291
309
* @throws ClientException
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ public function credential()
70
70
*/
71
71
public function httpClient ()
72
72
{
73
+ if ($ this ->httpClient ){
74
+ return $ this ->httpClient ;
75
+ }
76
+
73
77
if (!AlibabaCloud::all ()) {
74
78
if (CredentialsProvider::hasCustomChain ()) {
75
79
CredentialsProvider::customProvider ($ this ->client );
Original file line number Diff line number Diff line change @@ -107,6 +107,17 @@ public function testHttpClient()
107
107
$ request ->httpClient ();
108
108
}
109
109
110
+ /**
111
+ * @throws ClientException
112
+ */
113
+ public function testCustomHttpClient ()
114
+ {
115
+ $ httpClient = AlibabaCloud::accessKeyClient ('key ' , 'secret ' )
116
+ ->regionId ('cn-hangzhou ' );
117
+ $ request = AlibabaCloud::rpc ()->withHttpClient ($ httpClient );
118
+ self ::assertEquals ($ httpClient ,$ request ->httpClient );
119
+ }
120
+
110
121
/**
111
122
* @throws ClientException
112
123
*/
You can’t perform that action at this time.
0 commit comments