diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
index d7bd225..a009f6c 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
@@ -68,7 +68,7 @@ protected function setUp() {
     }
 
     // Set user agent to be consistent with WebTestBase.
-    $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix;
+    \Drupal::request()->server->set('HTTP_USER_AGENT', $this->databasePrefix);
 
     $this->setup = TRUE;
   }
