Ad
How To "mock" Sentry Client In The PHPUnit Tests
In case if you need to test PHP application error handlers, you have to "mock" or just disable sending errors on remote servers in the Sentry client. What is the right way to do this?
Ad
Answer
This is the example for Laravel, but this approach should work for any framework.
use Sentry\Client;
use Sentry\EventFactory;
use Sentry\Options;
use Sentry\Serializer\RepresentationSerializer;
use Sentry\Serializer\Serializer;
use Sentry\Transport\NullTransport;
private function mockSentry(): void
{
/** @var \Sentry\State\Hub $sentry */
$sentry = $this->app['sentry']; // Get sentry object from Laravel's container
$client = new Client(
new Options(),
new NullTransport(),
new EventFactory(
new Serializer(new Options()),
new RepresentationSerializer(new Options()),
new Options(),
'1',
'1',
),
);
$sentry->bindClient($client);
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad