/
HttpClientTracingPassTest.php
73 lines (61 loc) · 2.66 KB
/
HttpClientTracingPassTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Sentry\SentryBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\DependencyInjection\Compiler\HttpClientTracingPass;
use Sentry\SentryBundle\Tracing\HttpClient\TraceableHttpClient;
use Sentry\State\HubAdapter;
use Sentry\State\HubInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class HttpClientTracingPassTest extends TestCase
{
public static function setUpBeforeClass(): void
{
if (!self::isHttpClientPackageInstalled()) {
self::markTestSkipped('This test requires the "symfony/http-client" Composer package to be installed.');
}
}
/**
* @param array<string, mixed> $params
*
* @dataProvider provideDisableContainerParameters
*/
public function testShouldNotDecorateHttpClientServicesIfDisabled(array $params): void
{
$container = new ContainerBuilder(new ParameterBag($params));
$container->register('http.client', HttpClient::class)
->setPublic(true)
->addTag('http_client.client');
$container->addCompilerPass(new HttpClientTracingPass());
$container->compile();
self::assertEquals(HttpClient::class, $container->getDefinition('http.client')->getClass());
}
/**
* @return iterable<mixed[]>
*/
public function provideDisableContainerParameters(): iterable
{
yield [['sentry.tracing.enabled' => true, 'sentry.tracing.http_client.enabled' => false]];
yield [['sentry.tracing.enabled' => false, 'sentry.tracing.http_client.enabled' => false]];
yield [['sentry.tracing.enabled' => false, 'sentry.tracing.http_client.enabled' => true]];
}
public function testShouldDecorateHttpClients(): void
{
$container = new ContainerBuilder(new ParameterBag(['sentry.tracing.enabled' => true, 'sentry.tracing.http_client.enabled' => true]));
$container->register(HubInterface::class)
->setFactory([HubAdapter::class, 'getInstance']);
$container->register('http.client', HttpClient::class)
->setPublic(true)
->addTag('http_client.client');
$container->addCompilerPass(new HttpClientTracingPass());
$container->compile();
self::assertEquals(TraceableHttpClient::class, $container->findDefinition('http.client')->getClass());
}
private static function isHttpClientPackageInstalled(): bool
{
return interface_exists(HttpClientInterface::class);
}
}