function ResourceResponseTestTrait::sortResourceCollection

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortResourceCollection()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortResourceCollection()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortResourceCollection()

Sorts a collection of resources or resource identifiers.

This is useful for asserting collections or resources where order cannot be known in advance.

Parameters

array $resources: The resource or resource identifier.

1 call to ResourceResponseTestTrait::sortResourceCollection()
ResourceTestBase::assertSameDocument in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Asserts that an expected document matches the response body.

File

core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php, line 290

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function sortResourceCollection(array &$resources) {
    usort($resources, function ($a, $b) {
        return strcmp("{$a['type']}:{$a['id']}", "{$b['type']}:{$b['id']}");
    });
}

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