
| Current Path : /var/www/html/rocksensor1/web/core/modules/serialization/tests/src/Kernel/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor1/web/core/modules/serialization/tests/src/Kernel/SerializationTest.php |
<?php
declare(strict_types=1);
namespace Drupal\Tests\serialization\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
/**
* Functional tests for serialization system.
*
* @group serialization
*/
class SerializationTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['serialization', 'serialization_test'];
/**
* The serializer service to test.
*
* @var \Symfony\Component\Serializer\SerializerInterface
*/
protected $serializer;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->serializer = $this->container->get('serializer');
}
/**
* Confirms that modules can register normalizers and encoders.
*/
public function testSerializerComponentRegistration(): void {
$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.
}
}
}