function FieldItemNormalizerTest::testNormalizeFieldItemWithoutProperties

Same name and namespace in other branches
  1. 10 core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\FieldItemNormalizerTest::testNormalizeFieldItemWithoutProperties()
  2. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\FieldItemNormalizerTest::testNormalizeFieldItemWithoutProperties()

Tests a field item that has no properties.

@covers ::normalize

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php, line 60

Class

FieldItemNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21jsonapi%21src%21Normalizer%21FieldItemNormalizer.php/class/FieldItemNormalizer/9" title="Converts the Drupal field item object to a JSON:API array structure." class="local">\Drupal\jsonapi\Normalizer\FieldItemNormalizer</a> @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeFieldItemWithoutProperties() : void {
    $item = $this->prophesize(FieldItemInterface::class);
    $item->getProperties(TRUE)
        ->willReturn([]);
    $item->getValue()
        ->willReturn('Direct call to getValue');
    $result = $this->normalizer
        ->normalize($item->reveal(), 'api_json');
    assert($result instanceof CacheableNormalization);
    $this->assertSame('Direct call to getValue', $result->getNormalization());
}

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