SerializationTest.php in Drupal 10
File
core/modules/serialization/tests/src/Kernel/SerializationTest.php
View source
<?php
namespace Drupal\Tests\serialization\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
class SerializationTest extends KernelTestBase {
protected static $modules = [
'serialization',
'serialization_test',
];
protected $serializer;
protected function setUp() : void {
parent::setUp();
$this->serializer = $this->container
->get('serializer');
}
public function testSerializerComponentRegistration() {
$object = new \stdClass();
$format = 'serialization_test';
$expected = 'Normalized by SerializationTestNormalizer, Encoded by SerializationTestEncoder';
$this
->assertSame($expected, $this->serializer
->serialize($object, $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) {
}
}
}