Skip to content
Closed
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
56 changes: 55 additions & 1 deletion tests/DependencyInjection/Compiler/HttpClientTracingPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\DependencyInjection\Compiler\HttpClientTracingPass;
use Sentry\SentryBundle\Tracing\HttpClient\AbstractTraceableHttpClient;
use Sentry\SentryBundle\Tracing\HttpClient\TraceableHttpClient;
use Sentry\State\Hub;
use Sentry\State\HubInterface;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\HttpClient\ScopingHttpClient;

final class HttpClientTracingPassTest extends TestCase
{
Expand Down Expand Up @@ -54,6 +59,55 @@ public function processDataProvider(): \Generator
];
}

public function testScopedClients(): void
{
$container = $this->createContainerBuilder(true, true);

$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.project_dir', '');
$container->setParameter('kernel.container_class', '');
$container->setParameter('kernel.build_dir', '');
$container->setParameter('kernel.charset', '');
$container->setParameter('kernel.cache_dir', '');
$container->setParameter('kernel.logs_dir', '');
$container->setParameter('kernel.runtime_environment', 'dev');

$frameworkExtension = new FrameworkExtension();
$frameworkExtension->load(
[
'framework' => [
'http_client' => [
'scoped_clients' => [
'scoped.http.client' => [
'base_uri' => 'https://example.com',
],
],
],
],
],
$container
);

$container->getDefinition('scoped.http.client')->setPublic(true);
$container->compile();

$service = $container->get('scoped.http.client');
$this->assertInstanceOf(AbstractTraceableHttpClient::class, $service);

$reflection = new \ReflectionProperty(AbstractTraceableHttpClient::class, 'client');
$reflection->setAccessible(true);
$parentClient = $reflection->getValue($service);
$this->assertInstanceOf(ScopingHttpClient::class, $parentClient);

$reflection = new \ReflectionProperty(\get_class($parentClient), 'client');
$reflection->setAccessible(true);
$thirdClient = $reflection->getValue($parentClient);
// Failing check
$this->assertNotInstanceOf(AbstractTraceableHttpClient::class, $thirdClient);

// $this->assertInstanceOf(CurlHttpClient::class, $thirdClient);
}

/**
* @dataProvider processDoesNothingIfConditionsForEnablingTracingAreMissingDataProvider
*/
Expand Down Expand Up @@ -93,7 +147,7 @@ private function createContainerBuilder(bool $isTracingEnabled, bool $isHttpClie
$container->setParameter('sentry.tracing.enabled', $isTracingEnabled);
$container->setParameter('sentry.tracing.http_client.enabled', $isHttpClientTracingEnabled);

$container->register(HubInterface::class, HubInterface::class)
$container->register(HubInterface::class, Hub::class)
->setPublic(true);

$container->register($httpClientServiceId, HttpClientInterface::class)
Expand Down