function ComplexDataNormalizerTest::testNormalizeNonComplex

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeNonComplex()
  2. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeNonComplex()
  3. 10 core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest::testNormalizeNonComplex()

Tests normalize() where $object does not implement ComplexDataInterface.

Normalizers extending ComplexDataNormalizer may have a different supported class.

@covers ::normalize

File

core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php, line 89

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeNonComplex() : void {
    $normalizer = new TestExtendedNormalizer();
    $serialization_context = [
        'test' => 'test',
    ];
    $serializer_prophecy = $this->prophesize(Serializer::class);
    $serializer_prophecy->normalize('A', static::TEST_FORMAT, $serialization_context)
        ->willReturn('A-normalized')
        ->shouldBeCalled();
    $serializer_prophecy->normalize('B', static::TEST_FORMAT, $serialization_context)
        ->willReturn('B-normalized')
        ->shouldBeCalled();
    $normalizer->setSerializer($serializer_prophecy->reveal());
    $stdClass = new \stdClass();
    $stdClass->a = 'A';
    $stdClass->b = 'B';
    $normalized = $normalizer->normalize($stdClass, static::TEST_FORMAT, $serialization_context);
    $this->assertEquals([
        'a' => 'A-normalized',
        'b' => 'B-normalized',
    ], $normalized);
}

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