Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(agent): improve phpunit instrumentation #725

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions agent/lib_phpunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ NR_PHP_WRAPPER(nr_phpunit_instrument_testresult_endtest) {
}

/*
* PHPUnit 6+ started passing "tests skipped due to dependency failures"
* to the endTest method -- however, we already catch these tests in
* PHPUnit passes "tests skipped due to dependency failures"
* to the endTest method. For PHPUnit 5.x, we already catch these tests in
* our nr_phpunit_instrument_testresult_adderror wrapper. This check
* ensures these skipped tests aren't double counted by bailing if
* a test's status isn't set.
Expand All @@ -490,8 +490,13 @@ NR_PHP_WRAPPER(nr_phpunit_instrument_testresult_endtest) {
duration = nr_php_arg_get(2, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
if (!nr_php_is_zval_valid_double(duration)) {
nrl_verbosedebug(NRL_INSTRUMENT, "%s: invalid test duration", __func__);
NR_PHP_WRAPPER_CALL;
goto end;
/*
* When PHPUnit 6.x+ passes "tests skipped due to dependency failures"
* to the endTest method the second argument - $time - has the value of 0.
* However Zend Engine does not correctly set the type for this argument
* in this case and therefore we need to fix the type of duration here:
*/
ZVAL_DOUBLE(duration, 0.0);
}

NR_PHP_WRAPPER_CALL;
Expand Down Expand Up @@ -689,7 +694,4 @@ void nr_phpunit_enable(TSRMLS_D) {
nr_php_wrap_user_function(
NR_PSTR("PHPUnit_Framework_TestResult::addError"),
nr_phpunit_instrument_testresult_adderror TSRMLS_CC);
nr_php_wrap_user_function(
NR_PSTR("PHPUnit\\Framework\\TestResult::addError"),
nr_phpunit_instrument_testresult_adderror TSRMLS_CC);
}
7 changes: 3 additions & 4 deletions agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,10 @@ static nr_library_table_t libraries[] = {

/*
* The first path is for Composer installs, the second is for
* /usr/local/bin. While BaseTestRunner isn't the very first file to load,
* it contains the test status constants and loads before tests can run.
* /usr/local/bin.
*/
{"PHPUnit", "phpunit/src/runner/basetestrunner.php", nr_phpunit_enable},
{"PHPUnit", "phpunit/runner/basetestrunner.php", nr_phpunit_enable},
{"PHPUnit", "phpunit/src/framework/test.php", nr_phpunit_enable},
{"PHPUnit", "phpunit/framework/test.php", nr_phpunit_enable},

{"Predis", "predis/src/client.php", nr_predis_enable},
{"Predis", "predis/client.php", nr_predis_enable},
Expand Down
Loading