class SerializationTest
Same name and namespace in other branches
- 11.x core/modules/serialization/tests/src/Kernel/SerializationTest.php \Drupal\Tests\serialization\Kernel\SerializationTest
- 10 core/modules/serialization/tests/src/Kernel/SerializationTest.php \Drupal\Tests\serialization\Kernel\SerializationTest
- 8.9.x core/modules/serialization/tests/src/Kernel/SerializationTest.php \Drupal\Tests\serialization\Kernel\SerializationTest
Functional tests for serialization system.
@group serialization
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\serialization\Kernel\SerializationTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of SerializationTest
File
-
core/
modules/ serialization/ tests/ src/ Kernel/ SerializationTest.php, line 13
Namespace
Drupal\Tests\serialization\KernelView source
class SerializationTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
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() {
$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.
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.