-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): Add additional custom error handler tests.
Added additional error tests to exercise a variety of return values from a custom error handler.
- Loading branch information
Showing
6 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should capture and report errors along with a stack trace | ||
when a custom error handler exists but it returns false for a handled | ||
error. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.0", "<")) { | ||
die("skip: PHP < 7.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
/*EXPECT_REGEX | ||
^\s*(PHP )?Deprecated:\s*Let this serve as a deprecation* | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
[ | ||
"?? agent run id", | ||
[ | ||
[ | ||
"?? when", | ||
"OtherTransaction/php__FILE__", | ||
"Let this serve as a deprecation", | ||
"E_USER_DEPRECATED", | ||
{ | ||
"stack_trace": "??", | ||
"agentAttributes": "??", | ||
"intrinsics": "??" | ||
}, | ||
"?? transaction ID" | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "E_USER_DEPRECATED", | ||
"error.message": "Let this serve as a deprecation", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
function errorHandlerOne($errno, $errstr, $errfile, $errline) | ||
{ | ||
switch ($errno) { | ||
case E_USER_DEPRECATED: | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
// set to the user defined error handler | ||
$old_error_handler = set_error_handler("errorHandlerOne"); | ||
|
||
|
||
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED); | ||
|
||
echo("Let this serve as a warning"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should NOT capture and report error types | ||
when a custom error handler exists but it returns true for that error type. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.0", "<")) { | ||
die("skip: PHP < 7.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
/*EXPECT_REGEX | ||
Let this serve as a warning | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS null */ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
function errorHandlerOne($errno, $errstr, $errfile, $errline) | ||
{ | ||
switch ($errno) { | ||
case E_USER_DEPRECATED: | ||
return; | ||
} | ||
return false; | ||
} | ||
|
||
// set to the user defined error handler | ||
$old_error_handler = set_error_handler("errorHandlerOne"); | ||
|
||
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED); | ||
|
||
echo("Let this serve as a warning"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should NOT capture and report error types | ||
when a custom error handler exists but it returns true for those error types. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.0", "<")) { | ||
die("skip: PHP < 7.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
/*EXPECT_REGEX | ||
Let this serve as a warning | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS null */ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
function errorHandlerOne($errno, $errstr, $errfile, $errline) | ||
{ | ||
switch ($errno) { | ||
case E_USER_DEPRECATED: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// set to the user defined error handler | ||
$old_error_handler = set_error_handler("errorHandlerOne"); | ||
|
||
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED); | ||
|
||
echo("Let this serve as a warning"); | ||
|
||
|
100 changes: 100 additions & 0 deletions
100
tests/integration/errors/test_error_handler_with_fatal_error.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should capture and report E_COMPILE_ERROR even if a custom error handler | ||
exists and attempts to handle E_COMPILE_ERROR | ||
However, the following fatal error types | ||
cannot be handled with a user defined function: | ||
E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING | ||
It will therefore ignore the custom error handler. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
/*EXPECT_REGEX | ||
^\s*(PHP )?Warning:\s*Private methods cannot be final as they are never overridden by other classes | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
[ | ||
"?? agent run id", | ||
[ | ||
[ | ||
"?? when", | ||
"OtherTransaction/php__FILE__", | ||
"Private methods cannot be final as they are never overridden by other classes", | ||
"E_COMPILE_WARNING", | ||
{ | ||
"stack_trace": [], | ||
"agentAttributes": "??", | ||
"intrinsics": "??" | ||
}, | ||
"?? transaction ID" | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "E_COMPILE_WARNING", | ||
"error.message": "Private methods cannot be final as they are never overridden by other classes", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
function errorHandlerOne($errno, $errstr, $errfile, $errline) | ||
{ | ||
echo("Nothing to see here ever apparently."); | ||
switch ($errno) { | ||
case E_COMPILE_WARNING: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// set to the user defined error handler | ||
$old_error_handler = set_error_handler("errorHandlerOne"); | ||
|
||
class Foo { | ||
final private static function compileWarning(){ | ||
echo 'Compile warning',"\n"; | ||
} | ||
} | ||
|
Oops, something went wrong.