diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dee415f48..e4921fc52e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: - { version: '8.2', phpunit: '^9.6.21' } - { version: '8.3', phpunit: '^9.6.21' } - { version: '8.4', phpunit: '^9.6.21' } + - { version: '8.5', phpunit: '^9.6.25' } dependencies: - lowest - highest diff --git a/tests/phpt-oom/out_of_memory_fatal_error_increases_memory_limit.phpt b/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt similarity index 95% rename from tests/phpt-oom/out_of_memory_fatal_error_increases_memory_limit.phpt rename to tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt index acef1edd94..321ed418a1 100644 --- a/tests/phpt-oom/out_of_memory_fatal_error_increases_memory_limit.phpt +++ b/tests/phpt-oom/php84/out_of_memory_fatal_error_increases_memory_limit.phpt @@ -1,5 +1,10 @@ --TEST-- Test that when handling a out of memory error the memory limit is increased with 5 MiB and the event is serialized and ready to be sent +--SKIPIF-- += 80400) { + die('skip - only works for PHP 8.4 and below'); +} --INI-- memory_limit=67108864 --FILE-- diff --git a/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt b/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt new file mode 100644 index 0000000000..92e0305881 --- /dev/null +++ b/tests/phpt-oom/php85/out_of_memory_fatal_error_increases_memory_limit.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test that when handling a out of memory error the memory limit is increased with 5 MiB and the event is serialized and ready to be sent +--SKIPIF-- + 'http://public@example.com/sentry/1', +]); + +$transport = new class(new PayloadSerializer($options)) implements TransportInterface { + private $payloadSerializer; + + public function __construct(PayloadSerializerInterface $payloadSerializer) + { + $this->payloadSerializer = $payloadSerializer; + } + + public function send(Event $event): Result + { + $serialized = $this->payloadSerializer->serialize($event); + + echo 'Transport called' . \PHP_EOL; + + return new Result(ResultStatus::success()); + } + + public function close(?int $timeout = null): Result + { + return new Result(ResultStatus::success()); + } +}; + +$options->setTransport($transport); + +$client = (new ClientBuilder($options))->getClient(); + +SentrySdk::init()->bindClient($client); + +echo 'Before OOM memory limit: ' . \ini_get('memory_limit'); + +register_shutdown_function(function () { + echo 'After OOM memory limit: ' . \ini_get('memory_limit'); +}); + +$array = []; +for ($i = 0; $i < 100000000; ++$i) { + $array[] = 'sentry'; +} +--EXPECTF-- +Before OOM memory limit: 67108864 +Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d +Stack trace: +%A +Transport called +After OOM memory limit: 72351744 diff --git a/tests/phpt/error_handler_captures_fatal_error.phpt b/tests/phpt/php84/error_handler_captures_fatal_error.phpt similarity index 94% rename from tests/phpt/error_handler_captures_fatal_error.phpt rename to tests/phpt/php84/error_handler_captures_fatal_error.phpt index e7b457d2b6..2c4b9143bd 100644 --- a/tests/phpt/error_handler_captures_fatal_error.phpt +++ b/tests/phpt/php84/error_handler_captures_fatal_error.phpt @@ -1,5 +1,10 @@ --TEST-- Test catching fatal errors +--SKIPIF-- += 80500) { + die('skip - only works for PHP 8.4 and below'); +} --FILE-- = 80500) { + die('skip - only works for PHP 8.4 and below'); +} --INI-- memory_limit=67108864 --FILE-- diff --git a/tests/phpt/fatal_error_integration_captures_fatal_error.phpt b/tests/phpt/php84/fatal_error_integration_captures_fatal_error.phpt similarity index 93% rename from tests/phpt/fatal_error_integration_captures_fatal_error.phpt rename to tests/phpt/php84/fatal_error_integration_captures_fatal_error.phpt index ba82e9bcaa..2c8e40c4d7 100644 --- a/tests/phpt/fatal_error_integration_captures_fatal_error.phpt +++ b/tests/phpt/php84/fatal_error_integration_captures_fatal_error.phpt @@ -1,5 +1,10 @@ --TEST-- Test that the FatalErrorListenerIntegration integration captures only the errors allowed by the error_types option +--SKIPIF-- += 80500) { + die('skip - only works for PHP 8.4 and below'); +} --FILE-- = 80500) { + die('skip - only works for PHP 8.4 and below'); +} --FILE-- '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 method (JsonSerializable::jsonSerialize) in %s on line %d +Stack trace: +%A +Transport called +Fatal error listener called diff --git a/tests/phpt/php85/error_handler_captures_out_of_memory_fatal_error.phpt b/tests/phpt/php85/error_handler_captures_out_of_memory_fatal_error.phpt new file mode 100644 index 0000000000..cd3986d9c7 --- /dev/null +++ b/tests/phpt/php85/error_handler_captures_out_of_memory_fatal_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test catching out of memory fatal error without increasing memory limit +--SKIPIF-- +addFatalErrorHandlerListener(static function (): void { + echo 'Fatal error listener called' . PHP_EOL; + + echo 'After OOM memory limit: ' . ini_get('memory_limit'); +}); + +$errorHandler->setMemoryLimitIncreaseOnOutOfMemoryErrorInBytes(null); + +echo 'Before OOM memory limit: ' . ini_get('memory_limit'); + +$foo = str_repeat('x', 1024 * 1024 * 1024); +?> +--EXPECTF-- +Before OOM memory limit: 67108864 +Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d +Stack trace: +%A +Fatal error listener called +After OOM memory limit: 67108864 diff --git a/tests/phpt/php85/fatal_error_integration_captures_fatal_error.phpt b/tests/phpt/php85/fatal_error_integration_captures_fatal_error.phpt new file mode 100644 index 0000000000..88fdd8f5cc --- /dev/null +++ b/tests/phpt/php85/fatal_error_integration_captures_fatal_error.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test that the FatalErrorListenerIntegration integration captures only the errors allowed by the error_types option +--SKIPIF-- + false, + 'integrations' => [ + new FatalErrorListenerIntegration(), + ], +]); + +$client = (new ClientBuilder($options)) + ->setTransport($transport) + ->getClient(); + +SentrySdk::getCurrentHub()->bindClient($client); + +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 method (JsonSerializable::jsonSerialize) in %s on line %d +Stack trace: +%A +Transport called diff --git a/tests/phpt/php85/fatal_error_integration_respects_error_types_option.phpt b/tests/phpt/php85/fatal_error_integration_respects_error_types_option.phpt new file mode 100644 index 0000000000..7d74233ce5 --- /dev/null +++ b/tests/phpt/php85/fatal_error_integration_respects_error_types_option.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test that the FatalErrorListenerIntegration integration captures only the errors allowed by the error_types option +--SKIPIF-- + E_ALL & ~E_ERROR, + 'default_integrations' => false, + 'integrations' => [ + new FatalErrorListenerIntegration(), + ], +]); + +$client = (new ClientBuilder($options)) + ->setTransport($transport) + ->getClient(); + +SentrySdk::getCurrentHub()->bindClient($client); + +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 method (JsonSerializable::jsonSerialize) in %s on line %d +Stack trace: +%A