From f94ac97c1aedcb221f80624737f007ac42231ac4 Mon Sep 17 00:00:00 2001 From: Benoit Galati Date: Tue, 19 May 2020 21:45:33 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20Sentry=20deprecated=20in?= =?UTF-8?q?=20tests=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/SentryHandlerTest.php | 48 ++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/tests/SentryHandlerTest.php b/tests/SentryHandlerTest.php index 181a349..d046128 100644 --- a/tests/SentryHandlerTest.php +++ b/tests/SentryHandlerTest.php @@ -11,14 +11,16 @@ use Monolog\Formatter\LineFormatter; use Monolog\Logger; use PHPUnit\Framework\TestCase; -use Sentry\Breadcrumb; use Sentry\ClientBuilder; use Sentry\Event; +use Sentry\Options; use Sentry\Severity; use Sentry\State\Hub; use Sentry\State\Scope; use Sentry\Transport\ClosableTransportInterface; use Sentry\Transport\NullTransport; +use Sentry\Transport\TransportFactoryInterface; +use Sentry\Transport\TransportInterface; class SentryHandlerTest extends TestCase { @@ -39,7 +41,7 @@ protected function setUp(): void $this->transport = new SpyTransport(); $clientBuilder = ClientBuilder::create(['default_integrations' => false]); - $clientBuilder->setTransport($this->transport); + $clientBuilder->setTransportFactory(new FakeTransportFactory($this->transport)); $client = $clientBuilder->getClient(); @@ -515,18 +517,18 @@ public function resetSpy(): void /** * @return array{ - * "exception": array, - * "breadcrumbs": array, - * "message": string, - * "level": string, - * "event_id": string, - * "timestamp": int, - * "platform": string, - * "server_name": string, - * "extra": array, - * "sdk": string, - * "contexts": array - * } + * "exception": array, + * "breadcrumbs": array, + * "message": string, + * "level": string, + * "event_id": string, + * "timestamp": int, + * "platform": string, + * "server_name": string, + * "extra": array, + * "sdk": string, + * "contexts": array + * } */ public function getSpiedEventsAsArray(): array { @@ -544,3 +546,21 @@ public function close(?int $timeout = null): PromiseInterface return new FulfilledPromise(true); } } + +class FakeTransportFactory implements TransportFactoryInterface +{ + /** + * @var SpyTransport + */ + private $transport; + + public function __construct(SpyTransport $transport) + { + $this->transport = $transport; + } + + public function create(Options $options): TransportInterface + { + return $this->transport; + } +}