Skip to content
Snippets Groups Projects
Verified Commit 697f9880 authored by Dave Long's avatar Dave Long
Browse files

Fix some migrate tests; drupal_generate_test_ua() can generate warnings, which...

Fix some migrate tests; drupal_generate_test_ua() can generate warnings, which trigger different paths in PHPUnit 9 vs 10.
parent 55ea2449
No related branches found
No related tags found
2 merge requests!8035Closes #3446203,!6326drop-symfony-phpunit-bridge
......@@ -235,6 +235,9 @@ function drupal_valid_test_ua($new_prefix = NULL) {
/**
* Generates a user agent string with a HMAC and timestamp for tests.
*
* @return string|null
* The user agent, or NULL on failure.
*/
function drupal_generate_test_ua($prefix) {
static $key, $last_prefix;
......@@ -259,7 +262,9 @@ function drupal_generate_test_ua($prefix) {
// Generate and save a new hash salt for a test run.
// Consumed by drupal_valid_test_ua() before settings.php is loaded.
$private_key = Crypt::randomBytesBase64(55);
file_put_contents($key_file, $private_key);
if (!@file_put_contents($key_file, $private_key)) {
return NULL;
}
}
// The file properties add more entropy not easily accessible to others.
$key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
......
......@@ -23,8 +23,8 @@ public function __invoke() {
// database prefix were stored statically in a file or database variable.
return function ($handler) {
return function (RequestInterface $request, array $options) use ($handler) {
if ($test_prefix = drupal_valid_test_ua()) {
$request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
if ($user_agent = drupal_generate_test_ua(drupal_valid_test_ua())) {
$request = $request->withHeader('User-Agent', $user_agent);
}
return $handler($request, $options)
->then(function (ResponseInterface $response) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment