SerializationTest.php in Zircon Profile 8.0
File
core/modules/serialization/src/Tests/SerializationTest.php
View source
<?php
namespace Drupal\serialization\Tests;
use Drupal\simpletest\KernelTestBase;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
class SerializationTest extends KernelTestBase {
public static $modules = array(
'serialization',
'serialization_test',
);
protected $serializer;
protected function setUp() {
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
->assertIdentical($this->serializer
->serialize($object, $format), $expected);
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) {
$this
->pass('The serializer threw an exception for an unsupported format.');
}
}
}