-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
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 | ||
Check failure on line 28 in tests/SentryStubV3.php GitHub Actions / Static analysis
Check failure on line 28 in tests/SentryStubV3.php GitHub Actions / Static analysis
|
||
{ | ||
$this->spiedEvent = $event; | ||
|
||
return new FulfilledPromise(new Response(ResponseStatus::skipped(), $event)); | ||
Check failure on line 32 in tests/SentryStubV3.php GitHub Actions / Static analysis
Check failure on line 32 in tests/SentryStubV3.php GitHub Actions / Static analysis
Check failure on line 32 in tests/SentryStubV3.php GitHub Actions / Static analysis
|
||
} | ||
|
||
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 | ||
Check failure on line 50 in tests/SentryStubV3.php GitHub Actions / Static analysis
Check failure on line 50 in tests/SentryStubV3.php GitHub Actions / Static analysis
|
||
{ | ||
$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; | ||
} | ||
} |
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()); | ||
} | ||
} |
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; | ||
} | ||
} |