diff --git a/core/modules/file/tests/file_test/src/FileTestHelper.php b/core/modules/file/tests/file_test/src/FileTestHelper.php
index 9a5bc42dfbd4050e29214cc17faa168fb2fac7a5..9a364110415696a126c1a0edb8571371d4212eb5 100644
--- a/core/modules/file/tests/file_test/src/FileTestHelper.php
+++ b/core/modules/file/tests/file_test/src/FileTestHelper.php
@@ -30,14 +30,14 @@ public static function reset(): void {
       'move' => [],
       'delete' => [],
     ];
-    \Drupal::state()->set('file_test.results', $results);
+    \Drupal::keyValue('file_test')->set('results', $results);
 
     // These hooks will return these values, see FileTestHelper::setReturn().
     $return = [
       'validate' => [],
       'download' => NULL,
     ];
-    \Drupal::state()->set('file_test.return', $return);
+    \Drupal::keyValue('file_test')->set('return', $return);
   }
 
   /**
@@ -57,7 +57,7 @@ public static function reset(): void {
    * @see Drupal\file_test\FileTestHelper::reset()
    */
   public static function getCalls($op): array {
-    $results = \Drupal::state()->get('file_test.results', []);
+    $results = \Drupal::keyValue('file_test')->get('results', []);
     return $results[$op];
   }
 
@@ -70,7 +70,7 @@ public static function getCalls($op): array {
    *   parameters passed to each call.
    */
   public static function getAllCalls(): array {
-    return \Drupal::state()->get('file_test.results', []);
+    return \Drupal::keyValue('file_test')->get('results', []);
   }
 
   /**
@@ -87,9 +87,9 @@ public static function getAllCalls(): array {
    */
   public static function logCall($op, $args): void {
     if (\Drupal::state()->get('file_test.count_hook_invocations', TRUE)) {
-      $results = \Drupal::state()->get('file_test.results', []);
+      $results = \Drupal::keyValue('file_test')->get('results', []);
       $results[$op][] = $args;
-      \Drupal::state()->set('file_test.results', $results);
+      \Drupal::keyValue('file_test')->set('results', $results);
     }
   }
 
@@ -105,9 +105,10 @@ public static function logCall($op, $args): void {
    * @see Drupal\file_test\FileTestHelper::reset()
    */
   public static function setReturn($op, $value): void {
-    $return = \Drupal::state()->get('file_test.return', []);
+    $return = \Drupal::keyValue('file_test')->get('return', []);
+
     $return[$op] = $value;
-    \Drupal::state()->set('file_test.return', $return);
+    \Drupal::keyValue('file_test')->set('return', $return);
   }
 
   /**
diff --git a/core/modules/file/tests/file_test/src/Hook/FileTestHooks.php b/core/modules/file/tests/file_test/src/Hook/FileTestHooks.php
index 267e2ada834cc0de08789bc953919226ebf976e8..c58c2eba4fd0093af371d52cad2835443b7e0f65 100644
--- a/core/modules/file/tests/file_test/src/Hook/FileTestHooks.php
+++ b/core/modules/file/tests/file_test/src/Hook/FileTestHooks.php
@@ -212,7 +212,7 @@ public function entityTypeAlter(&$entity_types) : void {
    * @see Drupal\file_test\FileTestHelper::reset()
    */
   public function getReturn($op): array|int|null {
-    $return = \Drupal::state()->get('file_test.return', [$op => NULL]);
+    $return = \Drupal::keyValue('file_test')->get('return', [$op => NULL]);
     return $return[$op];
   }
 
diff --git a/core/modules/file/tests/src/Functional/DownloadTest.php b/core/modules/file/tests/src/Functional/DownloadTest.php
index d90ec492487c091de7a9aab49df81e8ad4269712..ddbb1868744c597dc4e4271c435e9006aea7190f 100644
--- a/core/modules/file/tests/src/Functional/DownloadTest.php
+++ b/core/modules/file/tests/src/Functional/DownloadTest.php
@@ -105,7 +105,7 @@ protected function doPrivateFileTransferTest(): void {
     $this->assertSession()->responseHeaderDoesNotExist('x-drupal-cache');
     $this->assertSession()->statusCodeEquals(200);
     // Ensure hook_file_download is fired correctly.
-    $this->assertEquals($file->getFileUri(), \Drupal::state()->get('file_test.results')['download'][0][0]);
+    $this->assertEquals($file->getFileUri(), FileTestHelper::getCalls('download')[0][0]);
 
     // Test that the file transferred correctly.
     $this->assertSame($contents, $this->getSession()->getPage()->getContent(), 'Contents of the file are correct.');
@@ -117,7 +117,7 @@ protected function doPrivateFileTransferTest(): void {
     $response = $http_client->head($not_found_url, ['http_errors' => FALSE]);
     $this->assertSame(404, $response->getStatusCode(), 'Correctly returned 404 response for a non-existent file.');
     // Assert that hook_file_download is not called.
-    $this->assertEquals([], \Drupal::state()->get('file_test.results')['download']);
+    $this->assertEquals([], FileTestHelper::getCalls('download'));
 
     // Having tried a non-existent file, try the original file again to ensure
     // it's returned instead of a 404 response.
@@ -143,7 +143,7 @@ protected function doPrivateFileTransferTest(): void {
     $this->drupalGet('/system/files');
     $this->assertSession()->statusCodeEquals(404);
     // Assert that hook_file_download is not called.
-    $this->assertEquals([], \Drupal::state()->get('file_test.results')['download']);
+    $this->assertEquals([], FileTestHelper::getCalls('download'));
   }
 
   /**