Skip to content

Commit

Permalink
Merge pull request #10 from msmakouz/bugfix/state-binding
Browse files Browse the repository at this point in the history
Adding existence StateInterface check
  • Loading branch information
butschster committed Jun 12, 2023
2 parents eb98872 + a52852d commit 84a9c60
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Client.php
Expand Up @@ -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());

Expand Down
21 changes: 21 additions & 0 deletions tests/Sentry/ClientTest.php
Expand Up @@ -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));
}
}

0 comments on commit 84a9c60

Please sign in to comment.