-
-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy patherror_handler_captures_fatal_error.phpt
More file actions
78 lines (62 loc) · 1.97 KB
/
error_handler_captures_fatal_error.phpt
File metadata and controls
78 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--TEST--
Test catching fatal errors
--SKIPIF--
<?php
if (PHP_VERSION_ID >= 80500) {
die('skip - only works for PHP 8.4 and below');
}
--FILE--
<?php
declare(strict_types=1);
namespace Sentry\Tests;
use Sentry\ClientBuilder;
use Sentry\ErrorHandler;
use Sentry\Event;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\Transport\Result;
use Sentry\Transport\ResultStatus;
use Sentry\Transport\TransportInterface;
$vendor = __DIR__;
while (!file_exists($vendor . '/vendor')) {
$vendor = dirname($vendor);
}
require $vendor . '/vendor/autoload.php';
$transport = new class implements TransportInterface {
public function send(Event $event): Result
{
echo 'Transport called' . PHP_EOL;
return new Result(ResultStatus::success());
}
public function close(?int $timeout = null): Result
{
return new Result(ResultStatus::success());
}
};
$options = [
'dsn' => 'http://public@example.com/sentry/1',
];
$client = ClientBuilder::create($options)
->setTransport($transport)
->getClient();
SentrySdk::getCurrentHub()->bindClient($client);
$errorHandler = ErrorHandler::registerOnceErrorHandler();
$errorHandler->addErrorHandlerListener(static function (): void {
echo 'Error listener called (it should not have been)' . PHP_EOL;
});
$errorHandler = ErrorHandler::registerOnceFatalErrorHandler();
$errorHandler->addFatalErrorHandlerListener(static function (): void {
echo 'Fatal error listener called' . PHP_EOL;
});
$errorHandler = ErrorHandler::registerOnceExceptionHandler();
$errorHandler->addExceptionHandlerListener(static function (): void {
echo 'Exception listener called (it should not have been)' . PHP_EOL;
});
final class TestClass implements \JsonSerializable
{
}
?>
--EXPECTF--
Fatal error: Class Sentry\Tests\TestClass contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (JsonSerializable::jsonSerialize) in %s on line %d
Transport called
Fatal error listener called