You are here

protected function SortArrayTest::assertBothNegativePositiveOrZero in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php \Drupal\Tests\Component\Utility\SortArrayTest::assertBothNegativePositiveOrZero()
  2. 9 core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php \Drupal\Tests\Component\Utility\SortArrayTest::assertBothNegativePositiveOrZero()

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".

@internal

Parameters

int $expected: Expected comparison function return value.

int $result: Actual comparison function return value.

4 calls to SortArrayTest::assertBothNegativePositiveOrZero()
SortArrayTest::testSortByTitleElement in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByTitleElement() input against expected output.
SortArrayTest::testSortByTitleProperty in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByTitleProperty() input against expected output.
SortArrayTest::testSortByWeightElement in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByWeightElement() input against expected output.
SortArrayTest::testSortByWeightProperty in core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
Tests SortArray::sortByWeightProperty() input against expected output.

File

core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php, line 320

Class

SortArrayTest
Tests the SortArray component.

Namespace

Drupal\Tests\Component\Utility

Code

protected function assertBothNegativePositiveOrZero(int $expected, int $result) : void {
  $this
    ->assertIsNumeric($expected);
  $this
    ->assertIsNumeric($result);
  $message = "Numbers should be both negative, both positive or both zero. Expected: {$expected}, actual: {$result}";
  if ($expected > 0) {
    $this
      ->assertGreaterThan(0, $result, $message);
  }
  elseif ($expected < 0) {
    $this
      ->assertLessThan(0, $result, $message);
  }
  else {
    $this
      ->assertEquals(0, $result, $message);
  }
}