You are here

protected function SortArrayTest::assertBothNegativePositiveOrZero in Drupal 9

Same name and namespace in other branches
  1. 8 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".

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 318

Class

SortArrayTest
Tests the SortArray component.

Namespace

Drupal\Tests\Component\Utility

Code

protected function assertBothNegativePositiveOrZero($expected, $result) {
  $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);
  }
}