You are here

protected function EntityResourceTestBase::assertEntityArraySubset in Drupal 9

Recursively asserts that the expected items are set in the tested entity.

A response may include more properties, we only need to ensure that all items in the request exist in the response.

Parameters

$expected: An array of expected values, may contain further nested arrays.

$actual: The object to test.

1 call to EntityResourceTestBase::assertEntityArraySubset()
EntityResourceTestBase::assertStoredEntityMatchesSentNormalization in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Asserts that the stored entity matches the sent normalization.

File

core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php, line 1449

Class

EntityResourceTestBase
Even though there is the generic EntityResource, it's necessary for every entity type to have its own test, because they each have different fields, validation constraints, et cetera. It's not because the generic case works, that every case…

Namespace

Drupal\Tests\rest\Functional\EntityResource

Code

protected function assertEntityArraySubset($expected, $actual) {
  foreach ($expected as $key => $value) {
    if (is_array($value)) {
      $this
        ->assertEntityArraySubset($value, $actual[$key]);
    }
    else {
      $this
        ->assertSame($value, $actual[$key]);
    }
  }
}