Skip to content

Commit 6378fb4

Browse files
committed
Map integrations config to options
1 parent 7c35397 commit 6378fb4

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/DependencyInjection/SentryExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
9393
if (\array_key_exists('before_breadcrumb', $processedOptions)) {
9494
$this->mapCallableValue($options, 'setBeforeBreadcrumbCallback', $processedOptions['before_breadcrumb']);
9595
}
96+
97+
if (\array_key_exists('integrations', $processedOptions)) {
98+
$integrations = [];
99+
foreach ($processedOptions['integrations'] as $integrationName) {
100+
$integrations[] = new Reference(substr($integrationName, 1));
101+
}
102+
103+
$options->addMethodCall('setIntegrations', [$integrations]);
104+
}
96105
}
97106

98107
/**

test/DependencyInjection/SentryExtensionTest.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Sentry\Breadcrumb;
77
use Sentry\Event;
8+
use Sentry\Integration\IntegrationInterface;
89
use Sentry\Options;
910
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
1011
use Sentry\SentryBundle\EventListener\ConsoleListener;
@@ -28,8 +29,9 @@ public function testDataProviderIsMappingTheRightNumberOfOptions(): void
2829
$providerData = $this->optionsValueProvider();
2930
$supportedOptions = \array_unique(\array_column($providerData, 0));
3031

32+
// subtracted one is `integration`, which cannot be tested with the provider
3133
$this->assertCount(
32-
ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT,
34+
ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT - 1,
3335
$supportedOptions,
3436
'Provider for configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
3537
);
@@ -280,6 +282,19 @@ public function testBeforeBreadcrumbWithInvalidServiceReference(): void
280282
$this->getOptionsFrom($container)->getBeforeBreadcrumbCallback();
281283
}
282284

285+
public function testIntegrations(): void
286+
{
287+
$container = $this->getContainer([
288+
'options' => [
289+
'integrations' => ['@integration_mock'],
290+
],
291+
]);
292+
293+
$integrations = $this->getOptionsFrom($container)->getIntegrations();
294+
$this->assertContainsOnlyInstancesOf(IntegrationMock::class, $integrations);
295+
$this->assertCount(1, $integrations);
296+
}
297+
283298
private function getContainer(array $configuration = []): Container
284299
{
285300
$containerBuilder = new ContainerBuilder();
@@ -290,11 +305,9 @@ private function getContainer(array $configuration = []): Container
290305
}
291306
$containerBuilder->setParameter('kernel.environment', 'test');
292307

293-
$mockEventDispatcher = $this
294-
->createMock(EventDispatcherInterface::class);
308+
$mockEventDispatcher = $this->createMock(EventDispatcherInterface::class);
295309

296-
$mockRequestStack = $this
297-
->createMock(RequestStack::class);
310+
$mockRequestStack = $this->createMock(RequestStack::class);
298311

299312
$containerBuilder->set('request_stack', $mockRequestStack);
300313
$containerBuilder->set('event_dispatcher', $mockEventDispatcher);
@@ -306,6 +319,9 @@ private function getContainer(array $configuration = []): Container
306319
$beforeSend->setFactory([CallbackMock::class, 'createCallback']);
307320
$containerBuilder->setDefinition('callable_mock', $beforeSend);
308321

322+
$integration = new Definition(IntegrationMock::class);
323+
$containerBuilder->setDefinition('integration_mock', $integration);
324+
309325
$extension = new SentryExtension();
310326
$extension->load(['sentry' => $configuration], $containerBuilder);
311327

@@ -347,3 +363,10 @@ public static function createCallback(): callable
347363
return [new self(), 'callback'];
348364
}
349365
}
366+
367+
class IntegrationMock implements IntegrationInterface
368+
{
369+
public function setupOnce(): void
370+
{
371+
}
372+
}

0 commit comments

Comments
 (0)