Skip to content

Commit 0abc664

Browse files
authored
Merge pull request #253 from getsentry/fix-hub-current-bug
Try to fix Hub bug introduced in #244
2 parents cba8329 + cd7d267 commit 0abc664

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Resources/config/services.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
</service>
1717

1818
<service id="Sentry\State\HubInterface" class="Sentry\State\Hub" public="false">
19-
<argument type="service" id="Sentry\ClientInterface" />
19+
<factory class="Sentry\SentryBundle\SentryBundle" method="getCurrentHub" />
20+
<call method="bindClient">
21+
<argument type="service" id="Sentry\ClientInterface" />
22+
</call>
2023
</service>
2124

2225
<service id="Sentry\SentryBundle\EventListener\ConsoleListener" class="Sentry\SentryBundle\EventListener\ConsoleListener" public="false">

test/DependencyInjection/SentryExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Jean85\PrettyVersions;
66
use Monolog\Logger as MonologLogger;
7+
use Prophecy\Argument;
78
use Sentry\Breadcrumb;
89
use Sentry\ClientInterface;
910
use Sentry\Event;
@@ -12,8 +13,10 @@
1213
use Sentry\Options;
1314
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
1415
use Sentry\SentryBundle\EventListener\ErrorListener;
16+
use Sentry\SentryBundle\SentryBundle;
1517
use Sentry\SentryBundle\Test\BaseTestCase;
1618
use Sentry\Severity;
19+
use Sentry\State\HubInterface;
1720
use Sentry\State\Scope;
1821
use Symfony\Component\DependencyInjection\Alias;
1922
use Symfony\Component\DependencyInjection\Container;
@@ -453,6 +456,10 @@ private function getContainer(array $configuration = []): Container
453456
$containerBuilder->setAlias(self::MONOLOG_HANDLER_TEST_PUBLIC_ALIAS, new Alias(Handler::class, true));
454457
}
455458

459+
$hub = $this->prophesize(HubInterface::class);
460+
$hub->bindClient(Argument::type(ClientMock::class));
461+
SentryBundle::setCurrentHub($hub->reveal());
462+
456463
$containerBuilder->compile();
457464

458465
return $containerBuilder;

test/SentryBundleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Sentry\SentryBundle\EventListener\ErrorListener;
1414
use Sentry\SentryBundle\EventListener\RequestListener;
1515
use Sentry\SentryBundle\EventListener\SubRequestListener;
16+
use Sentry\SentryBundle\SentryBundle;
17+
use Sentry\State\Hub;
1618
use Sentry\State\HubInterface;
1719
use Symfony\Component\Console\ConsoleEvents;
1820
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -158,6 +160,8 @@ private function getContainer(array $configuration = []): ContainerBuilder
158160
$extension = new SentryExtension();
159161
$extension->load(['sentry' => $configuration], $containerBuilder);
160162

163+
SentryBundle::setCurrentHub(new Hub());
164+
161165
return $containerBuilder;
162166
}
163167
}

0 commit comments

Comments
 (0)