/** * Interact with our bare API client to send a request. * @param string $httpMethod * @param string $apiUri * @param string $requestBody * @param bool $jsonRequestBodyFlag * @return mixed */ protected function sendApiRequest($httpMethod, $apiUri, $requestBody, $jsonRequestBodyFlag = false) { if ($jsonRequestBodyFlag) { return $this->apiTransport->sendSynchronousJsonApiRequest($httpMethod, $apiUri, $requestBody); } return $this->apiTransport->sendSynchronousPlainTextApiRequest($httpMethod, $apiUri, $requestBody); }
/** * @dataProvider provideSendSynchronousApiRequestKicksOffHTTPClientTestData * @param string $requestBody * @param bool $isRequestBodyJsonFlag */ public function testSendSynchronousApiRequestKicksOffExpectedRequestOnHTTPClient($requestBody, $isRequestBodyJsonFlag) { $httpMethod = 'GET'; $apiUri = 'whatever'; $username = '******'; $password = '******'; $httpClient = $this->getMock(HttpClient::class, ['request']); $expectedHeaderContentType = $isRequestBodyJsonFlag ? 'application/json' : 'text/plain'; $expectedHeadersArray = ['auth' => [$username, $password], 'body' => $requestBody, 'headers' => ['Accept' => 'application/json', 'Content-Type' => $expectedHeaderContentType]]; $httpClient->expects($this->once())->method('request')->with($httpMethod, $apiUri, $expectedHeadersArray)->will($this->returnValue(new Response())); $transport = new Transport($username, $password, $httpClient); $transport->sendSynchronousApiRequest($httpMethod, $apiUri, $requestBody, $expectedHeaderContentType); }