diff --git a/src/Client.php b/src/Client.php index 7d985e6..65bae44 100644 --- a/src/Client.php +++ b/src/Client.php @@ -23,11 +23,11 @@ public function __construct( public function send(\Throwable $exception): ?EventId { - $state = $this->container->get(StateInterface::class); - $scope = new Scope(); - if ($state !== null) { + if ($this->container->has(StateInterface::class)) { + $state = $this->container->get(StateInterface::class); + $scope->setTags($state->getTags()); $scope->setExtras($state->getVariables()); diff --git a/tests/Sentry/ClientTest.php b/tests/Sentry/ClientTest.php index 60aed61..69cebef 100644 --- a/tests/Sentry/ClientTest.php +++ b/tests/Sentry/ClientTest.php @@ -36,4 +36,25 @@ public function testSend(): void $this->assertSame($eventId, $mainClient->send($errorException)); } + + public function testSendWithoutState(): void + { + $mainClient = new Client( + $client = m::mock(ClientInterface::class), + new Container() + ); + + $errorException = new \ErrorException('Test exception'); + + $client->shouldReceive('captureException') + ->once() + ->withArgs(function (\Throwable $exception) use ($errorException) { + return $errorException === $exception; + }) + ->andReturn( + $eventId = new EventId('c8c46e00bf53942206fd2ad9546daac2') + ); + + $this->assertSame($eventId, $mainClient->send($errorException)); + } } \ No newline at end of file