diff --git a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
index cd8eff7..71cec0c 100644
--- a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
@@ -35,7 +35,7 @@ class SortArrayTest extends UnitTestCase {
    */
   public function testSortByWeightElement($a, $b, $expected) {
     $result = SortArray::sortByWeightElement($a, $b);
-    $this->assertEquals($expected, $result);
+    $this->assertBothNegativePositiveOrZero($expected, $result);
   }
 
   /**
@@ -111,7 +111,7 @@ public function providerSortByWeightElement() {
    */
   public function testSortByWeightProperty($a, $b, $expected) {
     $result = SortArray::sortByWeightProperty($a, $b);
-    $this->assertEquals($expected, $result);
+    $this->assertBothNegativePositiveOrZero($expected, $result);
   }
 
   /**
@@ -187,7 +187,7 @@ public function providerSortByWeightProperty() {
    */
   public function testSortByTitleElement($a, $b, $expected) {
     $result = SortArray::sortByTitleElement($a, $b);
-    $this->assertEquals($expected, $result);
+    $this->assertBothNegativePositiveOrZero($expected, $result);
   }
 
   /**
@@ -256,7 +256,7 @@ public function providerSortByTitleElement() {
    */
   public function testSortByTitleProperty($a, $b, $expected) {
     $result = SortArray::sortByTitleProperty($a, $b);
-    $this->assertEquals($expected, $result);
+    $this->assertBothNegativePositiveOrZero($expected, $result);
   }
 
   /**
@@ -309,4 +309,28 @@ public function providerSortByTitleProperty() {
     return $tests;
   }
 
+  /**
+   * Asserts that numbers are either both negative, both positive or both zero.
+   *
+   * The exact values returned by comparison functions differ between PHP
+   * versions and are considered an "implementation detail".
+   *
+   * @param int $expected
+   *   Expected comparison function return value.
+   * @param int $result
+   *   Actual comparison function return value.
+   *
+   * @return bool
+   *   TRUE if the assertion passed; FALSE otherwise.
+   */
+  protected function assertBothNegativePositiveOrZero($expected, $result) {
+    if (!is_numeric($expected) || !is_numeric($result)) {
+      return $this->assertTrue(FALSE, 'Parameters are not numeric.');
+    }
+    if (($expected < 0 && $result < 0) || ($expected > 0 && $result > 0) || ($expected === 0 && $result === 0))  {
+      return $this->assertTrue(TRUE, 'Numbers are either both negative, both positive or both zero.');
+    }
+    $this->assertTrue(FALSE, 'Numbers are not either both negative, both positive or both zero.');
+  }
+
 }
