You are here

protected function EntityQueryAggregateTest::assertResults in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php \Drupal\KernelTests\Core\Entity\EntityQueryAggregateTest::assertResults()

Asserts the results as expected regardless of order between and in rows.

Parameters

array $expected: An array of the expected results.

bool $sorted:

3 calls to EntityQueryAggregateTest::assertResults()
EntityQueryAggregateTest::assertSortedResults in core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php
Asserts the results as expected regardless of order in rows.
EntityQueryAggregateTest::testAggregation in core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php
Tests aggregation support.
EntityQueryAggregateTest::testRepeatedExecution in core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php
Tests preparing a query and executing twice.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityQueryAggregateTest.php, line 628

Class

EntityQueryAggregateTest
Tests the Entity Query Aggregation API.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertResults($expected, $sorted = FALSE) {
  $found = TRUE;
  $expected_keys = array_keys($expected);
  foreach ($this->queryResult as $key => $row) {
    $keys = $sorted ? [
      $key,
    ] : $expected_keys;
    foreach ($keys as $key) {
      $expected_row = $expected[$key];
      if (!array_diff_assoc($row, $expected_row) && !array_diff_assoc($expected_row, $row)) {
        continue 2;
      }
    }
    $found = FALSE;
    break;
  }
  $this
    ->assertTrue($found, strtr('!expected expected, !found found', [
    '!expected' => print_r($expected, TRUE),
    '!found' => print_r($this->queryResult, TRUE),
  ]));
}