Skip to content

Commit

Permalink
Merge pull request #253 from getsentry/fix-hub-current-bug
Browse files Browse the repository at this point in the history
Try to fix Hub bug introduced in #244
  • Loading branch information
Jean85 committed Sep 30, 2019
2 parents cba8329 + cd7d267 commit 0abc664
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Resources/config/services.xml
Expand Up @@ -16,7 +16,10 @@
</service>

<service id="Sentry\State\HubInterface" class="Sentry\State\Hub" public="false">
<argument type="service" id="Sentry\ClientInterface" />
<factory class="Sentry\SentryBundle\SentryBundle" method="getCurrentHub" />
<call method="bindClient">
<argument type="service" id="Sentry\ClientInterface" />
</call>
</service>

<service id="Sentry\SentryBundle\EventListener\ConsoleListener" class="Sentry\SentryBundle\EventListener\ConsoleListener" public="false">
Expand Down
7 changes: 7 additions & 0 deletions test/DependencyInjection/SentryExtensionTest.php
Expand Up @@ -4,6 +4,7 @@

use Jean85\PrettyVersions;
use Monolog\Logger as MonologLogger;
use Prophecy\Argument;
use Sentry\Breadcrumb;
use Sentry\ClientInterface;
use Sentry\Event;
Expand All @@ -12,8 +13,10 @@
use Sentry\Options;
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
use Sentry\SentryBundle\EventListener\ErrorListener;
use Sentry\SentryBundle\SentryBundle;
use Sentry\SentryBundle\Test\BaseTestCase;
use Sentry\Severity;
use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Container;
Expand Down Expand Up @@ -453,6 +456,10 @@ private function getContainer(array $configuration = []): Container
$containerBuilder->setAlias(self::MONOLOG_HANDLER_TEST_PUBLIC_ALIAS, new Alias(Handler::class, true));
}

$hub = $this->prophesize(HubInterface::class);
$hub->bindClient(Argument::type(ClientMock::class));
SentryBundle::setCurrentHub($hub->reveal());

$containerBuilder->compile();

return $containerBuilder;
Expand Down
4 changes: 4 additions & 0 deletions test/SentryBundleTest.php
Expand Up @@ -13,6 +13,8 @@
use Sentry\SentryBundle\EventListener\ErrorListener;
use Sentry\SentryBundle\EventListener\RequestListener;
use Sentry\SentryBundle\EventListener\SubRequestListener;
use Sentry\SentryBundle\SentryBundle;
use Sentry\State\Hub;
use Sentry\State\HubInterface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -158,6 +160,8 @@ private function getContainer(array $configuration = []): ContainerBuilder
$extension = new SentryExtension();
$extension->load(['sentry' => $configuration], $containerBuilder);

SentryBundle::setCurrentHub(new Hub());

return $containerBuilder;
}
}

0 comments on commit 0abc664

Please sign in to comment.