Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ApiClient/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ final class Client implements ClientInterface
{
private readonly GuzzleClient $guzzle;

public function __construct()
public function __construct(array $guzzleConfig = [])
{
$this->guzzle = new GuzzleClient();
$this->guzzle = new GuzzleClient($guzzleConfig);
}

public function head(string $url, array $headers): Response
Expand Down
5 changes: 3 additions & 2 deletions lib/ApiClient/TicketparkApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class TicketparkApiClient

public function __construct(
private readonly string $apiKey,
private readonly string $apiSecret
private readonly string $apiSecret,
private readonly string $baseUrl = self::ROOT_URL,
) {
}

Expand Down Expand Up @@ -147,7 +148,7 @@ private function getUrl(string $path, array $parameters = []): string
$params = '?' . http_build_query($parameters);
}

return self::ROOT_URL . $path . $params;
return $this->baseUrl . $path . $params;
}

private function getValidAccessToken(): string
Expand Down
25 changes: 25 additions & 0 deletions test/ApiClient/TicketparkApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,29 @@ public function testGenerateTokensThrowsExceptionOnUnexpectedResponse()
$this->apiClient->setUserCredentials('username', 'secret');
$this->apiClient->generateTokens();
}

public function testGetWithOverwrittenBaseUrl()
{
$httpClient = $this->prophet->prophesize(ClientInterface::class);
$httpClient->get(
'https://overwritten.ticketpark.ch/path?foo=bar',
[
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer some-token'
]
)
->willReturn(new Response(200, '', []))
->shouldBeCalledOnce();

$apiClient = new TicketparkApiClient(
'apiKey',
'apiSecret',
'https://overwritten.ticketpark.ch'
);

$apiClient->setClient($httpClient->reveal());
$apiClient->setAccessToken('some-token');
$apiClient->get('/path', ['foo' => 'bar']);
}
}
Loading