/** * @test */ public function will_throw_infrastructure_exception_when_connection_error() { // given $username = "******"; $password = "******"; $this->client->shouldReceive('call')->withAnyArgs()->andThrow(TransportException::transportError("Some error")); // when $this->expectException(RepositoryInfrastructureException::class); $this->sut->createSessionIdByCredentials($username, $password); }
/** {@inheritdoc} */ public function send($endpoint, $payload) { try { $response = $this->httpAdapter->post($endpoint, ['Content-Type' => 'text/xml; charset=UTF-8'], $payload); } catch (HttpAdapterException $e) { throw TransportException::transportError($e); } if ($response->getStatusCode() !== 200) { throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode()); } return (string) $response->getBody(); }
/** {@inheritdoc} */ public function send($endpoint, $payload) { try { $request = $this->messageFactory->createRequest('POST', $endpoint, ['Content-Type' => 'text/xml; charset=UTF-8'], $payload); $response = $this->client->sendRequest($request); if ($response->getStatusCode() !== 200) { throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode()); } return (string) $response->getBody(); } catch (PsrHttpException $e) { $response = $e->getResponse(); throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode()); } catch (ClientException $e) { throw TransportException::transportError($e); } }