public function ComplexDataNormalizerTest::testNormalizeNonComplex in Drupal 9
Same name and namespace in other branches
- 8 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 90 - Contains \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest.
Class
- ComplexDataNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\ComplexDataNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalizeNonComplex() {
$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);
}