Skip to content

Commit

Permalink
Add more ClientBuilder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Oct 10, 2023
1 parent e1c176b commit 40be49e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
use Sentry\Client;
use Sentry\ClientBuilder;
use Sentry\Event;
use Sentry\HttpClient\HttpClient;
use Sentry\HttpClient\HttpClientInterface;
use Sentry\HttpClient\Response;
use Sentry\Integration\IntegrationInterface;
use Sentry\Options;
use Sentry\Transport\HttpTransport;
use Sentry\Transport\Result;
use Sentry\Transport\ResultStatus;
use Sentry\Transport\TransportInterface;

final class ClientBuilderTest extends TestCase
{
Expand Down Expand Up @@ -70,6 +77,41 @@ public function testCreateWithNoOptionsIsTheSameAsDefaultOptions(): void
ClientBuilder::create([])
);
}

public function testDefaultHttpClientAndTransport()
{
$options = new Options();
$clientBuilder = new ClientBuilder($options);

$this->assertInstanceOf(HttpClient::class, $clientBuilder->getHttpClient());
$this->assertInstanceOf(HttpTransport::class, $clientBuilder->getTransport());
}

public function testSettingCustomHttpClinet()
{
$httpClient = new CustomHttpClient();

$options = new Options([
'http_client' => $httpClient,
]);
$clientBuilder = new ClientBuilder($options);

$this->assertSame($httpClient, $clientBuilder->getHttpClient());
$this->assertInstanceOf(HttpTransport::class, $clientBuilder->getTransport());
}

public function testSettingCustomTransport()
{
$transport = new CustomTransport();

$options = new Options([
'transport' => $transport,
]);
$clientBuilder = new ClientBuilder($options);

$this->assertInstanceOf(HttpClient::class, $clientBuilder->getHttpClient());
$this->assertSame($transport, $clientBuilder->getTransport());
}
}

final class StubIntegration implements IntegrationInterface
Expand All @@ -78,3 +120,24 @@ public function setupOnce(): void
{
}
}

final class CustomHttpClient implements HttpClientInterface
{
public function sendRequest(string $requestData, Options $options): Response
{
return new Response(0, [], '');
}
}

final class CustomTransport implements TransportInterface
{
public function send(Event $event): Result
{
return new Result(ResultStatus::success());
}

public function close(?int $timeout = null): Result
{
return new Result(ResultStatus::success());
}
}

0 comments on commit 40be49e

Please sign in to comment.