-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from B-Galati/sentry-v4
✨ Support Sentry V4
- Loading branch information
Showing
6 changed files
with
180 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BGalati\MonologSentryHandler\Tests; | ||
|
||
use GuzzleHttp\Promise\FulfilledPromise; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
use Sentry\Event; | ||
use Sentry\Options; | ||
use Sentry\Response; | ||
use Sentry\ResponseStatus; | ||
use Sentry\Transport\TransportFactoryInterface; | ||
use Sentry\Transport\TransportInterface; | ||
|
||
class SpyTransport implements TransportInterface | ||
{ | ||
/** | ||
* @var Event|null | ||
*/ | ||
public $spiedEvent; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $isFlushed = false; | ||
|
||
public function send(Event $event): PromiseInterface | ||
{ | ||
$this->spiedEvent = $event; | ||
|
||
return new FulfilledPromise(new Response(ResponseStatus::skipped(), $event)); | ||
} | ||
|
||
public function resetSpy(): void | ||
{ | ||
$this->spiedEvent = null; | ||
$this->isFlushed = false; | ||
} | ||
|
||
public function getSpiedEvent(): Event | ||
{ | ||
if (null === $this->spiedEvent) { | ||
throw new \RuntimeException('No spied scope'); | ||
} | ||
|
||
return $this->spiedEvent; | ||
} | ||
|
||
public function close(?int $timeout = null): PromiseInterface | ||
{ | ||
$this->isFlushed = true; | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BGalati\MonologSentryHandler\Tests; | ||
|
||
use Sentry\Event; | ||
use Sentry\Transport\Result; | ||
use Sentry\Transport\ResultStatus; | ||
use Sentry\Transport\TransportInterface; | ||
|
||
class SpyTransport implements TransportInterface | ||
{ | ||
/** | ||
* @var Event|null | ||
*/ | ||
public $spiedEvent; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $isFlushed = false; | ||
|
||
public function send(Event $event): Result | ||
{ | ||
$this->spiedEvent = $event; | ||
|
||
return new Result(ResultStatus::skipped(), $event); | ||
} | ||
|
||
public function resetSpy(): void | ||
{ | ||
$this->spiedEvent = null; | ||
$this->isFlushed = false; | ||
} | ||
|
||
public function getSpiedEvent(): Event | ||
{ | ||
if (null === $this->spiedEvent) { | ||
throw new \RuntimeException('No spied scope'); | ||
} | ||
|
||
return $this->spiedEvent; | ||
} | ||
|
||
public function close(?int $timeout = null): Result | ||
{ | ||
$this->isFlushed = true; | ||
|
||
return new Result(ResultStatus::success()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BGalati\MonologSentryHandler\Tests; | ||
|
||
use BGalati\MonologSentryHandler\SentryHandler; | ||
use Sentry\Event; | ||
use Sentry\State\Scope; | ||
|
||
class SpySentryHandler extends SentryHandler | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
public $afterWriteCalled = false; | ||
|
||
protected function processScope(Scope $scope, $record, Event $sentryEvent): void | ||
{ | ||
$scope->setExtra('processScope', 'called'); | ||
} | ||
|
||
protected function afterWrite(): void | ||
{ | ||
$this->afterWriteCalled = true; | ||
|
||
parent::afterWrite(); | ||
} | ||
|
||
public function resetSpy(): void | ||
{ | ||
$this->afterWriteCalled = false; | ||
} | ||
} |