Skip to content

PHPC-2064: Change strategy for disabling SKIPIF caching #1301

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions tests/utils/basic-skipif.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ register_shutdown_function(function() {
exit(sprintf('skip %s: %s', errno_as_string($lastError['type']), $lastError['message']));
}
});

disable_skipif_caching_if_necessary();
28 changes: 21 additions & 7 deletions tests/utils/skipif.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,33 @@
require_once __DIR__ . '/basic.inc';
require_once __DIR__ . '/tools.php';

/**
* Disables SKIPIF caching (PHP 8.1+).
/* Disable SKIPIF caching on PHP 8.1+ if the current script calls any functions
* that cannot be cached. SkipCache (from run-tests.php) requires that "nocache"
* be printed before all other SKIPIF output, so this function should be called
* from basic-skipif.inc before test-level skip code.
*/
function disable_skipif_caching()
function disable_skipif_caching_if_necessary()
{
if (PHP_VERSION_ID < 80100) {
return;
}

$skipif = file_get_contents($_SERVER['PATH_TRANSLATED']);

if (strpos($skipif, 'skip_if_not_clean') === false) {
return;
}

/* Earlier versions of PHP 8.1.x discard SKIPIF output after consuming a
* leading "nocache" tag, which could prevent a test from being skipped. To
* avoid that, only print "nocache" as the final output. In the event the
* test does skip, this trailing "nocache" tag will be ignored, but that is
* preferable to ignoring the skip entirely. */
if (PHP_VERSION_ID < 80103) {
register_shutdown_function(function() { echo "nocache\n"; });
return;
}

echo "nocache\n";
}

Expand Down Expand Up @@ -432,10 +450,6 @@ function skip_if_not_clean($databaseName = DATABASE_NAME, $collectionName = COLL
} catch (RuntimeException $e) {
exit("skip Could not drop '$databaseName.$collectionName': " . $e->getMessage());
}

/* Since this function modifies the state of the database, we need it to run
* each time before a test. */
disable_skipif_caching();
}

function skip_if_no_getmore_failpoint()
Expand Down