From bef603487533cd8dca8b158d535a4c3ef85ef71a Mon Sep 17 00:00:00 2001 From: Benoit Galati Date: Sat, 3 Feb 2024 13:30:48 +0100 Subject: [PATCH] =?UTF-8?q?WIP=20=E2=9C=A8=20Support=20Sentry=20V4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 1 + composer.json | 2 +- tests/SentryHandlerTest.php | 93 +++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc030b2..9cb1ae7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/composer.json b/composer.json index 06d6576..4c5a542 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/SentryHandlerTest.php b/tests/SentryHandlerTest.php index 27e6854..94792e7 100644 --- a/tests/SentryHandlerTest.php +++ b/tests/SentryHandlerTest.php @@ -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; @@ -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) { + 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 + { + $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)); } - 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 + { + $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; + } } }