Skip to content

Commit

Permalink
fix(tests): Split tests to test error handling
Browse files Browse the repository at this point in the history
PHP used to accept less strongly typed error handlers without explicit parameters.
Starting with PHP 8.2, error handlers need to have explicit parameters.
As such, exceptions handled by old style error handlers will be correctly propagated for PHP 8.0/8.1,
but PHP 8.2 and above requires strongly typed error handlers.
  • Loading branch information
zsistla committed Oct 16, 2023
1 parent 38eb42d commit d139ac6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

/*DESCRIPTION
Test that span events are correctly created from any eligible segment, even
when an exception is handled by the exception handler. In the case of PHP 8.0/8.1,
PHP OAPI additionally where PHP OAPI additionally passes exception information in the
zend_execute_data for the agent to use to create an error_event.
when an exception is handled by the exception handler.
Check that error events are created.
*/

Expand All @@ -17,10 +15,6 @@
require('skipif.inc');
if (version_compare(PHP_VERSION, "8.2", ">=")) {
die("skip: PHP > 8.1 not supported\n");
}
*/

/*INI
Expand Down Expand Up @@ -177,7 +171,7 @@
*/

set_exception_handler(
function () {
function (Throwable $exception) {
time_nanosleep(0, 100000000);
exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

/*DESCRIPTION
Test that span events are correctly created from any eligible segment, even
when an exception is handled by the exception handler. Unlike the case of
PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the
zend_execute_data for the agent to use to create an error_event, PHP 8.2
passes no additional information for the error event to be recorded.
Check that no error events are created.
when an exception is handled by the exception handler. In the case of PHP 8.0/8.1,
the oldstyle error handler behaved as expected. Stronger typing requires
explicit parameters in the error handler for PHP 8.2+.
Check that error events are created.
*/

/*SKIPIF
<?php
if (version_compare(PHP_VERSION, "8.2", ">=")) {
die("skip: PHP > 8.1 not supported\n");
} else {
require('skipif.inc');
if (version_compare(PHP_VERSION, "8.2", "<")) {
die("skip: PHP > 8.2 not supported\n");
}
*/
Expand All @@ -45,7 +44,35 @@
*/

/*EXPECT_ERROR_EVENTS
null
[
"?? agent run id",
{
"reservoir_size": "??",
"events_seen": 1
},
[
[
{
"type": "TransactionError",
"timestamp": "??",
"error.class": "RuntimeException",
"error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??",
"transactionName": "OtherTransaction\/php__FILE__",
"duration": "??",
"databaseDuration": "??",
"databaseCallCount": "??",
"nr.transactionGuid": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??",
"spanId": "??"
},
{},
{}
]
]
]
*/


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

/*DESCRIPTION
Test that span events are correctly created from any eligible segment, even
when an exception is handled by the exception handler. Unlike the case of
PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the
zend_execute_data for the agent to use to create an error_event, PHP 8.2
passes no additional information for the error event to be recorded.
Check that no error events are created.
when an exception is handled by the exception handler. In the case of PHP 8.0/8.1,
PHP OAPI additionally where PHP OAPI additionally passes exception information in the
zend_execute_data for the agent to use to create an error_event.
Check that error events are created.
*/

/*SKIPIF
<?php
if (version_compare(PHP_VERSION, "8.2", ">=")) {
die("skip: PHP > 8.1 not supported\n");
}
//else {
require('skipif.inc');
//}
if (version_compare(PHP_VERSION, "8.2", "<")) {
die("skip: PHP > 8.2 not supported\n");
}
*/

/*INI
newrelic.distributed_tracing_enabled=1
Expand All @@ -40,7 +42,35 @@
*/

/*EXPECT_ERROR_EVENTS
null
[
"?? agent run id",
{
"reservoir_size": "??",
"events_seen": 1
},
[
[
{
"type": "TransactionError",
"timestamp": "??",
"error.class": "RuntimeException",
"error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??",
"transactionName": "OtherTransaction\/php__FILE__",
"duration": "??",
"databaseDuration": "??",
"databaseCallCount": "??",
"nr.transactionGuid": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??",
"spanId": "??"
},
{},
{}
]
]
]
*/

/*EXPECT_SPAN_EVENTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

/*DESCRIPTION
Test that span events are correctly created from any eligible segment, even
when an exception is handled by the exception handler. In the case of PHP 8.0/8.1,
PHP OAPI additionally where PHP OAPI additionally passes exception information in the
zend_execute_data for the agent to use to create an error_event.
when an exception is handled by the exception handler.
Check that error events are created.
*/

Expand All @@ -17,9 +15,6 @@
require('skipif.inc');
if (version_compare(PHP_VERSION, "8.2", ">=")) {
die("skip: PHP > 8.1 not supported\n");
}
*/

Expand All @@ -34,6 +29,8 @@
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=tracing
newrelic.loglevel = verbosedebug
newrelic.daemon.loglevel = debug
*/

/*PHPMODULES
Expand Down Expand Up @@ -173,7 +170,7 @@
*/

set_exception_handler(
function () {
function (Throwable $exception) {
time_nanosleep(0, 100000000);
exit(0);
}
Expand Down

0 comments on commit d139ac6

Please sign in to comment.