diff --git a/tests/src/Unit/TestSession.php b/tests/src/Unit/TestSession.php
index ec41c57a..a3da1321 100644
--- a/tests/src/Unit/TestSession.php
+++ b/tests/src/Unit/TestSession.php
@@ -2,148 +2,80 @@
 
 namespace Drupal\Tests\rules\Unit;
 
-use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
-use Symfony\Component\HttpFoundation\Session\SessionInterface;
-
-/**
- * Implements just the methods we need for the Rules unit tests.
- */
-class TestSession implements SessionInterface {
-
-  /**
-   * Simulated session storage.
-   *
-   * @var array
-   */
-  protected $logs = [];
-
-  /**
-   * {@inheritdoc}
-   */
-  public function all() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function clear() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function get($key, $default = NULL) {
-    if (isset($this->logs[$key])) {
-      return $this->logs[$key];
+// Symfony 6, which is used by Drupal 10, requires PHP 8 features that
+// are not available in PHP 7. Specifically, the 'mixed' return type hint.
+// @todo Remove this hack when Drupal 9 is no longer supported.
+// @see https://www.drupal.org/project/rules/issues/3265360
+if (version_compare(\Drupal::VERSION, '10') >= 0) {
+
+  /**
+   * Implements just the methods we need for the Rules unit tests.
+   */
+  class TestSession extends TestSessionBase {
+
+    /**
+     * {@inheritdoc}
+     */
+    public function get(string $key, mixed $default = NULL): mixed {
+      if (isset($this->logs[$key])) {
+        return $this->logs[$key];
+      }
+      else {
+        return $default;
+      }
     }
-    else {
-      return $default;
-    }
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getBag($name) {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getId() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getMetadataBag() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getName() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function has($name) {
-  }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function invalidate($lifetime = NULL) {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function isStarted() {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function migrate($destroy = FALSE, $lifetime = NULL) {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function registerBag(SessionBagInterface $bag) {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function remove($key) {
-    if (isset($this->logs[$key])) {
-      $return = $this->logs[$key];
-      unset($this->logs[$key]);
-      return $return;
-    }
-    else {
-      return NULL;
+    /**
+     * {@inheritdoc}
+     */
+    public function remove(string $key): mixed {
+      if (isset($this->logs[$key])) {
+        $return = $this->logs[$key];
+        unset($this->logs[$key]);
+        return $return;
+      }
+      else {
+        return NULL;
+      }
     }
-  }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function replace(array $attributes) {
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function save() {
-  }
+}
+// Otherwise use the PHP 7 compatible version of TestSession.
+else {
 
   /**
-   * {@inheritdoc}
+   * Implements just the methods we need for the Rules unit tests.
    */
-  public function set($key, $value) {
-    $this->logs[$key] = $value;
-  }
+  class TestSession extends TestSessionBase {
 
-  /**
-   * {@inheritdoc}
-   */
-  public function setId($id) {
-  }
+    /**
+     * {@inheritdoc}
+     */
+    public function get($key, $default = NULL) {
+      if (isset($this->logs[$key])) {
+        return $this->logs[$key];
+      }
+      else {
+        return $default;
+      }
+    }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function setName($name) {
-  }
+    /**
+     * {@inheritdoc}
+     */
+    public function remove($key) {
+      if (isset($this->logs[$key])) {
+        $return = $this->logs[$key];
+        unset($this->logs[$key]);
+        return $return;
+      }
+      else {
+        return NULL;
+      }
+    }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function start() {
   }
 
 }
diff --git a/tests/src/Unit/TestSessionBase.php b/tests/src/Unit/TestSessionBase.php
new file mode 100644
index 00000000..e4a5fd88
--- /dev/null
+++ b/tests/src/Unit/TestSessionBase.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Drupal\Tests\rules\Unit;
+
+use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
+
+/**
+ * Implements just the methods we need for the Rules unit tests.
+ */
+abstract class TestSessionBase implements SessionInterface {
+
+  /**
+   * Simulated session storage.
+   *
+   * @var array
+   */
+  protected $logs = [];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function all(): array {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function clear() {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getBag($name): SessionBagInterface {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getId(): string {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getMetadataBag(): MetadataBag {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getName(): string {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function has($name): bool {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function invalidate($lifetime = NULL): bool {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isStarted(): bool {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function migrate($destroy = FALSE, $lifetime = NULL): bool {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function registerBag(SessionBagInterface $bag) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function replace(array $attributes) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function save() {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function set($key, $value) {
+    $this->logs[$key] = $value;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setId($id) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setName($name) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function start(): bool {
+  }
+
+}
