9
9
use Sentry \SentryBundle \Tracing \HttpClient \TraceableHttpClient ;
10
10
use Sentry \State \HubInterface ;
11
11
use Symfony \Component \DependencyInjection \ContainerBuilder ;
12
- use Symfony \Component \HttpClient \HttpClient ;
13
12
use Symfony \Contracts \HttpClient \HttpClientInterface ;
14
13
15
14
final class HttpClientTracingPassTest extends TestCase
@@ -21,23 +20,49 @@ public static function setUpBeforeClass(): void
21
20
}
22
21
}
23
22
24
- public function testProcess (): void
23
+ /**
24
+ * @dataProvider processDataProvider
25
+ */
26
+ public function testProcess (string $ httpClientServiceId ): void
25
27
{
26
- $ container = $ this ->createContainerBuilder (true , true );
28
+ $ container = $ this ->createContainerBuilder (true , true , $ httpClientServiceId );
27
29
$ container ->compile ();
28
30
29
- $ this ->assertSame (TraceableHttpClient::class, $ container ->findDefinition ('http.client ' )->getClass ());
31
+ $ this ->assertSame (TraceableHttpClient::class, $ container ->getDefinition ($ httpClientServiceId )->getClass ());
32
+ }
33
+
34
+ public function processDataProvider (): \Generator
35
+ {
36
+ yield 'The framework version is >=6.3 ' => [
37
+ 'http_client.transport ' ,
38
+ ];
39
+
40
+ yield 'The framework version is <6.3 and the mocked HTTP client is decorated by the retryable client ' => [
41
+ 'http_client.retryable.inner.mock_client ' ,
42
+ ];
43
+
44
+ yield 'The framework version is <6.3 and the mocked HTTP client is decorated by the profiler ' => [
45
+ '.debug.http_client.inner.mock_client ' ,
46
+ ];
47
+
48
+ yield 'The framework version is <6.3 and the mocked HTTP client is not decorated ' => [
49
+ 'http_client.mock_client ' ,
50
+ ];
51
+
52
+ yield 'The framework version is <6.3 and the HTTP client is not mocked ' => [
53
+ 'http_client ' ,
54
+ ];
30
55
}
31
56
32
57
/**
33
58
* @dataProvider processDoesNothingIfConditionsForEnablingTracingAreMissingDataProvider
34
59
*/
35
60
public function testProcessDoesNothingIfConditionsForEnablingTracingAreMissing (bool $ isTracingEnabled , bool $ isHttpClientTracingEnabled ): void
36
61
{
37
- $ container = $ this ->createContainerBuilder ($ isTracingEnabled , $ isHttpClientTracingEnabled );
62
+ $ container = $ this ->createContainerBuilder ($ isTracingEnabled , $ isHttpClientTracingEnabled, ' http_client.transport ' );
38
63
$ container ->compile ();
39
64
40
- $ this ->assertSame (HttpClient ::class, $ container ->getDefinition ('http.client ' )->getClass ());
65
+ $ this ->assertSame (HttpClientInterface ::class, $ container ->getDefinition ('http_client.transport ' )->getClass ());
41
66
}
42
67
43
68
/**
@@ -61,7 +86,7 @@ public function processDoesNothingIfConditionsForEnablingTracingAreMissingDataPr
61
86
];
62
87
}
63
88
64
- private function createContainerBuilder (bool $ isTracingEnabled , bool $ isHttpClientTracingEnabled ): ContainerBuilder
89
+ private function createContainerBuilder (bool $ isTracingEnabled , bool $ isHttpClientTracingEnabled, string $ httpClientServiceId ): ContainerBuilder
65
90
{
66
91
$ container = new ContainerBuilder ();
67
92
$ container ->addCompilerPass (new HttpClientTracingPass ());
@@ -71,9 +96,8 @@ private function createContainerBuilder(bool $isTracingEnabled, bool $isHttpClie
71
96
$ container ->register (HubInterface::class, HubInterface::class)
72
97
->setPublic (true );
73
98
74
- $ container ->register ('http.client ' , HttpClient::class)
75
- ->setPublic (true )
76
- ->addTag ('http_client.client ' );
99
+ $ container ->register ($ httpClientServiceId , HttpClientInterface::class)
100
+ ->setPublic (true );
77
101
78
102
return $ container ;
79
103
}
0 commit comments