function SortTest::assertSorted

Same name in other branches
  1. 9 core/tests/Drupal/Tests/PhpCs/SortTest.php \Drupal\Tests\PhpCs\SortTest::assertSorted()
  2. 11.x core/tests/Drupal/Tests/PhpCs/SortTest.php \Drupal\Tests\PhpCs\SortTest::assertSorted()

A helper method to assert that an input array is sorted.

Compared by values, if the $column is not null, the column of the value is used for comparing.

Parameters

array $input: The input array.

null|string $column: The column of the value or NULL.

1 call to SortTest::assertSorted()
SortTest::testSorted in core/tests/Drupal/Tests/PhpCs/SortTest.php
Tests that the phpcs.xml.dist file is properly sorted.

File

core/tests/Drupal/Tests/PhpCs/SortTest.php, line 84

Class

SortTest
Tests that phpcs.xml.dist is properly sorted.

Namespace

Drupal\Tests\PhpCs

Code

private function assertSorted(array $input, ?string $column = NULL) {
    $input_sorted = $input;
    if ($column === NULL) {
        usort($input_sorted, static function ($a, $b) {
            return strcmp($a, $b);
        });
    }
    else {
        usort($input_sorted, static function ($a, $b) use ($column) {
            return strcmp($a[$column], $b[$column]);
        });
    }
    $this->assertEquals($input, $input_sorted);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.