Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a couple of tests and changelog line
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/DependencyInjection/Compiler/HttpClientTracingPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters