Skip to content

Commit

Permalink
convert test_php_execute.c into integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lavarou committed Dec 27, 2023
1 parent 067c002 commit 4aa7dec
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/php_execute/00.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
happy path - pass argument that will not throw exception.
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT
ok - uncaught(1)
*/


/*EXPECT_ERROR_EVENTS null */


require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

// call a function and don't trigger an exception
$retval = uncaught(1);

tap_equal(1, $retval, 'uncaught(1)');
42 changes: 42 additions & 0 deletions tests/php_execute/01.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
call a function and trigger an exception
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT_REGEX
^\s*Fatal error: Uncaught.*RuntimeException.*Division by zero.*
*/

/*EXPECT_ERROR_EVENTS
[
"?? agent run id",
{
"reservoir_size": 100,
"events_seen": 1
},
[
"?? error event"
]
]*/


require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

// call a function and don't trigger an exception
$retval = uncaught(1);

// call a function and trigger an exception
$retval = uncaught(0);

newrelic_end_transaction();
32 changes: 32 additions & 0 deletions tests/php_execute/02.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
call a function and trigger an exception that is caught
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT
ok - caught(0)
*/


/*EXPECT_ERROR_EVENTS null */


require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

// call a function and trigger an exception that is caught
$retval = caught(0);

newrelic_end_transaction();

tap_equal(1, $retval, 'caught(0)');
31 changes: 31 additions & 0 deletions tests/php_execute/03.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
call a function and trigger an exception that is caught
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT
ok - followup(0)
*/


/*EXPECT_ERROR_EVENTS null */


require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

$retval = followup(0);

newrelic_end_transaction();

tap_equal(1, $retval, 'followup(0)');
38 changes: 38 additions & 0 deletions tests/php_execute/04.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
call a function and trigger an exception that is caught but another uncaught exception is thrown
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT_REGEX
^\s*Fatal error: Uncaught.*RuntimeException.*Division by zero.*
*/


/*EXPECT_ERROR_EVENTS
[
"?? agent run id",
{
"reservoir_size": 100,
"events_seen": 1
},
[
"?? error event"
]
]*/

require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

$retval = followup_uncaught(0);

newrelic_end_transaction();
39 changes: 39 additions & 0 deletions tests/php_execute/05.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
call a function and trigger an exception that is caught then rethrown
*/

/*INI
display_errors=1
log_errors=0
*/

/*EXPECT_REGEX
^\s*Fatal error: Uncaught.*RuntimeException.*Rethrown caught exception.*Division by zero.*
*/


/*EXPECT_ERROR_EVENTS
[
"?? agent run id",
{
"reservoir_size": 100,
"events_seen": 1
},
[
"?? error event"
]
]*/


require_once(__DIR__.'/functions.inc');
require_once(__DIR__.'/../include/tap.php');

$retval = rethrow(0);

newrelic_end_transaction();
53 changes: 53 additions & 0 deletions tests/php_execute/functions.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

function three($a) {
if (0 == $a) {
throw new RuntimeException('Division by zero');
} else {
return $a;
}
}

function two($a) {
return three($a);
}

function uncaught($a) {
return two($a);
}

function caught($a) {
try {
two($a);
} catch (Exception $e) {
return 1;
}
return 1;
}

function followup($a) {
try {
two($a);
} catch (Exception $e) {
return three(1);
}
return three(1);
}

function followup_uncaught($a) {
try {
two($a);
} catch (Exception $e) {
return three(0);
}
return three(1);
}

function rethrow($a) {
try {
two($a);
} catch (Exception $e) {
throw new RuntimeException('Rethrown caught exception: '. $e->getMessage());
}
return three(1);
}

0 comments on commit 4aa7dec

Please sign in to comment.