Skip to content

Commit 88d680e

Browse files
authored
Merge pull request #5 from cloudloyalty/fixes
Fixes
2 parents 39ca802 + 52c695f commit 88d680e

4 files changed

Lines changed: 40 additions & 40 deletions

File tree

lib/Client.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ public function getServerAddress()
192192
*/
193193
public function setServerAddress($serverAddress)
194194
{
195-
$scheme = parse_url($this->serverAddress, PHP_URL_SCHEME);
196-
$scheme = $scheme ? $scheme . '://' : 'https://';
197-
$this->serverAddress = $scheme . trim($serverAddress, '/');
195+
$scheme = parse_url($serverAddress, PHP_URL_SCHEME);
196+
if (!$scheme) {
197+
$serverAddress = 'https://' . $serverAddress;
198+
}
199+
$this->serverAddress = rtrim($serverAddress, '/');
198200
return $this;
199201
}
200202

@@ -423,8 +425,18 @@ public function sendRawRequest($path, $rawBody)
423425

424426
if ($this->logger instanceof LoggerInterface) {
425427
$this->logger->debug('Request', [
426-
'request' => $request,
427-
'response' => $response,
428+
'request' => [
429+
'method' => $request->getMethod(),
430+
'uri' => $request->getUri(),
431+
'headers' => $request->getHeaders(),
432+
'body' => $request->getBody(),
433+
],
434+
'response' => [
435+
'statusCode' => $response->getStatusCode(),
436+
'reasonPhrase' => $response->getReasonPhrase(),
437+
'headers' => $response->getHeaders(),
438+
'body' => $response->getBody(),
439+
],
428440
]);
429441
}
430442

lib/Http/Request.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace CloudLoyalty\Api\Http;
44

5-
class Request implements RequestInterface, \JsonSerializable
5+
class Request implements RequestInterface
66
{
77
/**
88
* @var string
@@ -96,17 +96,4 @@ public function setBody($body)
9696
$this->body = $body;
9797
return $this;
9898
}
99-
100-
/**
101-
* @return array
102-
*/
103-
public function jsonSerialize()
104-
{
105-
return [
106-
'method' => $this->getMethod(),
107-
'uri' => $this->getUri(),
108-
'headers' => $this->getHeaders(),
109-
'body' => $this->getBody(),
110-
];
111-
}
11299
}

lib/Http/Response.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace CloudLoyalty\Api\Http;
44

5-
class Response implements ResponseInterface, \JsonSerializable
5+
class Response implements ResponseInterface
66
{
77
/**
88
* @var int
@@ -96,17 +96,4 @@ public function setBody($body)
9696
$this->body = $body;
9797
return $this;
9898
}
99-
100-
/**
101-
* @return array
102-
*/
103-
public function jsonSerialize()
104-
{
105-
return [
106-
'statusCode' => $this->getStatusCode(),
107-
'reasonPhrase' => $this->getReasonPhrase(),
108-
'headers' => $this->getHeaders(),
109-
'body' => $this->getBody(),
110-
];
111-
}
11299
}

tests/ClientTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,27 @@ public function testNewClientWhenCustomServerAddressSpecified()
137137
$apiClient->setServerAddress('api.someotherhost.com');
138138
$apiClient->setProcessingKey('test-key');
139139

140-
$apiClient->newClient(
141-
(new NewClientRequest())
142-
->setClient(
143-
(new ClientInfoQuery())
144-
->setName('Name')
145-
)
146-
);
140+
$apiClient->newClient(new NewClientRequest());
141+
}
142+
143+
public function testNewClientWhenCustomServerAddressWithSchemeSpecified()
144+
{
145+
$httpClientMock = $this->createMock('CloudLoyalty\Api\Http\Client\NativeClient');
146+
147+
$httpClientMock->expects($this->once())
148+
->method('sendRequest')
149+
->with($this->callback(function (Request $request) {
150+
$this->assertEquals('ftp://api.someotherhost.com/new-client', $request->getUri());
151+
152+
return true;
153+
}))
154+
->willReturn(new Response());
155+
156+
$apiClient = new Client([], $httpClientMock);
157+
$apiClient->setServerAddress('ftp://api.someotherhost.com');
158+
$apiClient->setProcessingKey('test-key');
159+
160+
$apiClient->newClient(new NewClientRequest());
147161
}
148162

149163
public function testNewClientWhenPsrLoggerProvided()

0 commit comments

Comments
 (0)