Skip to content

Commit 06d0436

Browse files
authored
test(integration): Add additional custom error handler tests (#869)
Added additional tests to exercise a variety of return values from a custom error handler.
1 parent 6def121 commit 06d0436

7 files changed

+551
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should capture and report errors along with a stack trace
9+
when a custom error handler exists but it returns false for a handled
10+
error.
11+
*/
12+
13+
/*SKIPIF
14+
<?php
15+
if (version_compare(PHP_VERSION, "7.0", "<")) {
16+
die("skip: PHP < 7.0.0 not supported\n");
17+
}
18+
*/
19+
20+
/*INI
21+
display_errors=1
22+
log_errors=0
23+
*/
24+
25+
/*EXPECT_REGEX
26+
^\s*(PHP )?Deprecated:\s*Let this serve as a deprecation*
27+
*/
28+
29+
/*EXPECT_TRACED_ERRORS
30+
[
31+
"?? agent run id",
32+
[
33+
[
34+
"?? when",
35+
"OtherTransaction/php__FILE__",
36+
"Let this serve as a deprecation",
37+
"E_USER_DEPRECATED",
38+
{
39+
"stack_trace": "??",
40+
"agentAttributes": "??",
41+
"intrinsics": "??"
42+
},
43+
"?? transaction ID"
44+
]
45+
]
46+
]
47+
*/
48+
49+
/*EXPECT_ERROR_EVENTS
50+
[
51+
"?? agent run id",
52+
{
53+
"reservoir_size": "??",
54+
"events_seen": 1
55+
},
56+
[
57+
[
58+
{
59+
"type": "TransactionError",
60+
"timestamp": "??",
61+
"error.class": "E_USER_DEPRECATED",
62+
"error.message": "Let this serve as a deprecation",
63+
"transactionName": "OtherTransaction\/php__FILE__",
64+
"duration": "??",
65+
"nr.transactionGuid": "??",
66+
"guid": "??",
67+
"sampled": true,
68+
"priority": "??",
69+
"traceId": "??",
70+
"spanId": "??"
71+
},
72+
{},
73+
{}
74+
]
75+
]
76+
]
77+
*/
78+
79+
function errorHandlerOne($errno, $errstr, $errfile, $errline)
80+
{
81+
switch ($errno) {
82+
case E_USER_DEPRECATED:
83+
return false;
84+
}
85+
return false;
86+
}
87+
88+
// set to the user defined error handler
89+
$old_error_handler = set_error_handler("errorHandlerOne");
90+
91+
92+
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED);
93+
94+
echo("Hello from happy path!");
95+
96+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should NOT capture and report error types
9+
when a custom error handler exists but it returns true for that error type.
10+
*/
11+
12+
/*SKIPIF
13+
<?php
14+
if (version_compare(PHP_VERSION, "7.0", "<")) {
15+
die("skip: PHP < 7.0.0 not supported\n");
16+
}
17+
*/
18+
19+
/*INI
20+
display_errors=1
21+
log_errors=0
22+
*/
23+
24+
/*EXPECT_REGEX
25+
Hello from happy path!
26+
*/
27+
28+
/*EXPECT_TRACED_ERRORS null */
29+
30+
/*EXPECT_ERROR_EVENTS null */
31+
32+
function errorHandlerOne($errno, $errstr, $errfile, $errline)
33+
{
34+
switch ($errno) {
35+
case E_USER_DEPRECATED:
36+
return;
37+
}
38+
return false;
39+
}
40+
41+
// set to the user defined error handler
42+
$old_error_handler = set_error_handler("errorHandlerOne");
43+
44+
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED);
45+
46+
echo("Hello from happy path!");
47+
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should NOT capture and report error types
9+
when a custom error handler exists but it returns true for those error types.
10+
*/
11+
12+
/*SKIPIF
13+
<?php
14+
if (version_compare(PHP_VERSION, "7.0", "<")) {
15+
die("skip: PHP < 7.0.0 not supported\n");
16+
}
17+
*/
18+
19+
/*INI
20+
display_errors=1
21+
log_errors=0
22+
*/
23+
24+
/*EXPECT_REGEX
25+
Hello from happy path!
26+
*/
27+
28+
/*EXPECT_TRACED_ERRORS null */
29+
30+
/*EXPECT_ERROR_EVENTS null */
31+
32+
function errorHandlerOne($errno, $errstr, $errfile, $errline)
33+
{
34+
switch ($errno) {
35+
case E_USER_DEPRECATED:
36+
return true;
37+
}
38+
return false;
39+
}
40+
41+
// set to the user defined error handler
42+
$old_error_handler = set_error_handler("errorHandlerOne");
43+
44+
trigger_error("Let this serve as a deprecation", E_USER_DEPRECATED);
45+
46+
echo("Hello from happy path!");
47+
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should capture and report E_COMPILE_ERROR even if a custom error handler
9+
exists and attempts to handle E_COMPILE_ERROR
10+
However, the following fatal error types
11+
cannot be handled with a user defined function:
12+
E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING
13+
It will therefore ignore the custom error handler.
14+
*/
15+
16+
/*SKIPIF
17+
<?php
18+
if (version_compare(PHP_VERSION, "8.0", "<")) {
19+
die("skip: PHP < 8.0.0 not supported\n");
20+
}
21+
*/
22+
23+
/*INI
24+
display_errors=1
25+
log_errors=0
26+
*/
27+
28+
/*EXPECT_REGEX
29+
^\s*(PHP )?Warning:\s*Private methods cannot be final as they are never overridden by other classes
30+
*/
31+
32+
/*EXPECT_TRACED_ERRORS
33+
[
34+
"?? agent run id",
35+
[
36+
[
37+
"?? when",
38+
"OtherTransaction/php__FILE__",
39+
"Private methods cannot be final as they are never overridden by other classes",
40+
"E_COMPILE_WARNING",
41+
{
42+
"stack_trace": [],
43+
"agentAttributes": "??",
44+
"intrinsics": "??"
45+
},
46+
"?? transaction ID"
47+
]
48+
]
49+
]
50+
*/
51+
52+
/*EXPECT_ERROR_EVENTS
53+
[
54+
"?? agent run id",
55+
{
56+
"reservoir_size": "??",
57+
"events_seen": 1
58+
},
59+
[
60+
[
61+
{
62+
"type": "TransactionError",
63+
"timestamp": "??",
64+
"error.class": "E_COMPILE_WARNING",
65+
"error.message": "Private methods cannot be final as they are never overridden by other classes",
66+
"transactionName": "OtherTransaction\/php__FILE__",
67+
"duration": "??",
68+
"nr.transactionGuid": "??",
69+
"guid": "??",
70+
"sampled": true,
71+
"priority": "??",
72+
"traceId": "??",
73+
"spanId": "??"
74+
},
75+
{},
76+
{}
77+
]
78+
]
79+
]
80+
*/
81+
82+
function errorHandlerOne($errno, $errstr, $errfile, $errline)
83+
{
84+
echo("Nothing to see here ever apparently.");
85+
switch ($errno) {
86+
case E_COMPILE_WARNING:
87+
return true;
88+
}
89+
return false;
90+
}
91+
92+
// set to the user defined error handler
93+
$old_error_handler = set_error_handler("errorHandlerOne");
94+
95+
class Foo {
96+
final private static function compileWarning(){
97+
echo 'Compile warning',"\n";
98+
}
99+
}
100+

0 commit comments

Comments
 (0)