function SortTest::testSorted

Same name in other branches
  1. 10 core/tests/Drupal/Tests/PhpCs/SortTest.php \Drupal\Tests\PhpCs\SortTest::testSorted()
  2. 10 core/tests/Drupal/Tests/CSpell/SortTest.php \Drupal\Tests\CSpell\SortTest::testSorted()
  3. 11.x core/tests/Drupal/Tests/PhpCs/SortTest.php \Drupal\Tests\PhpCs\SortTest::testSorted()
  4. 11.x core/tests/Drupal/Tests/CSpell/SortTest.php \Drupal\Tests\CSpell\SortTest::testSorted()

Tests that the phpcs.xml.dist file is properly sorted.

File

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

Class

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

Namespace

Drupal\Tests\PhpCs

Code

public function testSorted() {
    $content = file_get_contents($this->filePath);
    $xml_encoder = new XmlEncoder();
    $xml_encoded = $xml_encoder->decode($content, 'xml');
    $this->assertIsArray($xml_encoded);
    $top_level_keys = array_keys($xml_encoded);
    $this->assertSorted($top_level_keys);
    $this->assertArrayHasKey('file', $xml_encoded);
    $files = $xml_encoded['file'];
    $this->assertSorted($files);
    $this->assertArrayHasKey('exclude-pattern', $xml_encoded);
    $excluded_patterns = $xml_encoded['exclude-pattern'];
    $this->assertSorted($excluded_patterns);
    $this->assertArrayHasKey('rule', $xml_encoded);
    $rules = $xml_encoded['rule'];
    $this->assertSorted($rules, '@ref');
    foreach ($rules as $item) {
        if (array_key_exists('exclude', $item)) {
            $excluded = $item['exclude'];
            $excluded = array_filter($excluded, static function ($item) {
                return is_array($item) && array_key_exists('@name', $item);
            });
            $this->assertSorted($excluded, '@name');
        }
    }
}

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