You are here

public function ComplexDataNormalizerTest::testNormalizeComplexData in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeComplexData()

Tests normalizing complex data.

@covers ::normalize

File

core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php, line 59
Contains \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest.

Class

ComplexDataNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\ComplexDataNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeComplexData() {
  $serializer_prophecy = $this
    ->prophesize(Serializer::class);
  $non_internal_property = $this
    ->getTypedDataProperty(FALSE);
  $serializer_prophecy
    ->normalize($non_internal_property, static::TEST_FORMAT, [])
    ->willReturn('A-normalized')
    ->shouldBeCalled();
  $this->normalizer
    ->setSerializer($serializer_prophecy
    ->reveal());
  $complex_data = $this
    ->prophesize(ComplexDataInterface::class);
  $complex_data
    ->getProperties(TRUE)
    ->willReturn([
    'prop:a' => $non_internal_property,
    'prop:internal' => $this
      ->getTypedDataProperty(TRUE),
  ])
    ->shouldBeCalled();
  $normalized = $this->normalizer
    ->normalize($complex_data
    ->reveal(), static::TEST_FORMAT);
  $this
    ->assertEquals([
    'prop:a' => 'A-normalized',
  ], $normalized);
}