Skip to content

Commit

Permalink
WIP ✨ Support Sentry V4
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Galati committed Feb 3, 2024
1 parent fa21c6b commit bef6034
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- php: 8.1 # should use monolog v3
- php: 8.2 # should use monolog v3
- php: 8.3 # should use monolog v3
# TODO matrix should support Both versions of Sentry SDK
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"require": {
"php": "^7.4 || ^8.0",
"monolog/monolog": "^1.6 || ^2.0 || ^3.0",
"sentry/sentry": "^3.1"
"sentry/sentry": "^3.1 || ^4.0"
},
"require-dev": {
"coduo/php-matcher": "^6.0.8",
Expand Down
93 changes: 49 additions & 44 deletions tests/SentryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;
use Sentry\Breadcrumb;
use Sentry\Client;
use Sentry\ClientBuilder;
use Sentry\Event;
use Sentry\Integration\EnvironmentIntegration;
Expand Down Expand Up @@ -570,62 +571,66 @@ public function resetSpy(): void
}
}

class SpyTransport implements TransportInterface
{
/**
* @var Event|null
*/
public $spiedEvent;

/**
* @var bool
*/
public $isFlushed = false;

public function send(Event $event): PromiseInterface
if (defined(Client::class.'::SDK_VERSION') && version_compare(Client::SDK_VERSION, '4.0.0') >= 0) {

Check failure on line 574 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Comparison operation ">=" between 1 and 0 is always true.
dump('TODO');
} else {
class SpyTransport implements TransportInterface
{
$this->spiedEvent = $event;
/**
* @var Event|null
*/
public $spiedEvent;

return new FulfilledPromise(new Response(ResponseStatus::skipped(), $event));
}
/**
* @var bool
*/
public $isFlushed = false;

public function resetSpy(): void
{
$this->spiedEvent = null;
$this->isFlushed = false;
}
public function send(Event $event): PromiseInterface

Check failure on line 589 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method BGalati\MonologSentryHandler\Tests\SpyTransport::send() has invalid return type GuzzleHttp\Promise\PromiseInterface.

Check failure on line 589 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Return type GuzzleHttp\Promise\PromiseInterface of method BGalati\MonologSentryHandler\Tests\SpyTransport::send() is not covariant with return type Sentry\Transport\Result of method Sentry\Transport\TransportInterface::send().
{
$this->spiedEvent = $event;

public function getSpiedEvent(): Event
{
if (null === $this->spiedEvent) {
throw new \RuntimeException('No spied scope');
return new FulfilledPromise(new Response(ResponseStatus::skipped(), $event));

Check failure on line 593 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Call to static method skipped() on an unknown class Sentry\ResponseStatus.

Check failure on line 593 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Instantiated class GuzzleHttp\Promise\FulfilledPromise not found.

Check failure on line 593 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Instantiated class Sentry\Response not found.

Check failure on line 593 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method BGalati\MonologSentryHandler\Tests\SpyTransport::send() should return GuzzleHttp\Promise\PromiseInterface but returns GuzzleHttp\Promise\FulfilledPromise.
}

return $this->spiedEvent;
}
public function resetSpy(): void
{
$this->spiedEvent = null;
$this->isFlushed = false;
}

public function close(?int $timeout = null): PromiseInterface
{
$this->isFlushed = true;
public function getSpiedEvent(): Event
{
if (null === $this->spiedEvent) {
throw new \RuntimeException('No spied scope');
}

return new FulfilledPromise(true);
}
}
return $this->spiedEvent;
}

class FakeTransportFactory implements TransportFactoryInterface
{
/**
* @var SpyTransport
*/
private $transport;
public function close(?int $timeout = null): PromiseInterface

Check failure on line 611 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method BGalati\MonologSentryHandler\Tests\SpyTransport::close() has invalid return type GuzzleHttp\Promise\PromiseInterface.

Check failure on line 611 in tests/SentryHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Return type GuzzleHttp\Promise\PromiseInterface of method BGalati\MonologSentryHandler\Tests\SpyTransport::close() is not covariant with return type Sentry\Transport\Result of method Sentry\Transport\TransportInterface::close().
{
$this->isFlushed = true;

public function __construct(SpyTransport $transport)
{
$this->transport = $transport;
return new FulfilledPromise(true);
}
}

public function create(Options $options): TransportInterface
class FakeTransportFactory implements TransportFactoryInterface
{
return $this->transport;
/**
* @var SpyTransport
*/
private $transport;

public function __construct(SpyTransport $transport)
{
$this->transport = $transport;
}

public function create(Options $options): TransportInterface
{
return $this->transport;
}
}
}

0 comments on commit bef6034

Please sign in to comment.