function ComplexDataNormalizerTest::testNormalizeComplexData

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeComplexData()
  2. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeComplexData()
  3. 10 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 58

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeComplexData() : void {
    $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);
}

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