public function SerializationTest::testSerializerComponentRegistration in Drupal 9
Same name and namespace in other branches
- 8 core/modules/serialization/tests/src/Kernel/SerializationTest.php \Drupal\Tests\serialization\Kernel\SerializationTest::testSerializerComponentRegistration()
- 10 core/modules/serialization/tests/src/Kernel/SerializationTest.php \Drupal\Tests\serialization\Kernel\SerializationTest::testSerializerComponentRegistration()
Confirms that modules can register normalizers and encoders.
File
- core/
modules/ serialization/ tests/ src/ Kernel/ SerializationTest.php, line 37
Class
- SerializationTest
- Functional tests for serialization system.
Namespace
Drupal\Tests\serialization\KernelCode
public function testSerializerComponentRegistration() {
$object = new \stdClass();
$format = 'serialization_test';
$expected = 'Normalized by SerializationTestNormalizer, Encoded by SerializationTestEncoder';
// Ensure the serialization invokes the expected normalizer and encoder.
$this
->assertSame($expected, $this->serializer
->serialize($object, $format));
// Ensure the serialization fails for an unsupported format.
try {
$this->serializer
->serialize($object, 'unsupported_format');
$this
->fail('The serializer was expected to throw an exception for an unsupported format, but did not.');
} catch (UnexpectedValueException $e) {
// Expected exception; just continue testing.
}
}