Skip to content

Commit

Permalink
🔧 Fix Sentry deprecated in tests code
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Galati committed May 19, 2020
1 parent 808ce2c commit f94ac97
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions tests/SentryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();

Expand Down Expand Up @@ -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
{
Expand All @@ -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;
}
}

0 comments on commit f94ac97

Please sign in to comment.