@@ -61,6 +61,11 @@ class Connection extends Component
6161 * @var boolean Whether to user pluralisation or not
6262 */
6363 public $ usePluralisation = true ;
64+ /**
65+ * @var boolean Whether we are in test mode or not (prevent execution)
66+ */
67+ public $ isTestMode = false ;
68+
6469 /**
6570 * @var string|Closure authorization config
6671 */
@@ -265,7 +270,7 @@ public function getHandler()
265270 * @param string|array $url the URL for request, not including proto and site
266271 * @param array $data the request data
267272 *
268- * @return Response |false
273+ * @return mixed |false
269274 * @throws \yii\httpclient\Exception
270275 */
271276 protected function request ($ method , $ url , $ data = [])
@@ -280,14 +285,19 @@ protected function request($method, $url, $data = [])
280285
281286 Yii::beginProfile ($ profile , __METHOD__ );
282287 /* @var $request \yii\httpclient\Request */
288+
289+ Yii::debug ($ this ->handler ->baseUrl . '/ ' . $ url , __METHOD__ . '-url ' );
290+ Yii::debug ($ data , __METHOD__ . '-data ' );
291+ Yii::debug ($ headers , __METHOD__ . '-headers ' );
292+
283293 $ request = call_user_func ([$ this ->handler , $ method ], $ url , $ data , $ headers );
284- $ this ->_response = $ request ->send ();
294+ $ this ->_response = $ this -> isTestMode ? [] : $ request ->send ();
285295 Yii::endProfile ($ profile , __METHOD__ );
286296
287- if (!$ this ->_response ->isOk ) {
297+ if (!$ this ->isTestMode && ! $ this -> _response ->isOk ) {
288298 return false ;
289299 }
290300
291- return $ this ->_response ->data ;
301+ return $ this ->isTestMode ? [] : $ this -> _response ->data ;
292302 }
293303}
0 commit comments