comparison core/modules/serialization/tests/src/Kernel/SerializationTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\serialization\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6 use Symfony\Component\Serializer\Exception\UnexpectedValueException;
7
8 /**
9 * Functional tests for serialization system.
10 *
11 * @group serialization
12 */
13 class SerializationTest extends KernelTestBase {
14
15 /**
16 * Modules to enable.
17 *
18 * @var array
19 */
20 public static $modules = ['serialization', 'serialization_test'];
21
22 /**
23 * The serializer service to test.
24 *
25 * @var \Symfony\Component\Serializer\SerializerInterface
26 */
27 protected $serializer;
28
29 protected function setUp() {
30 parent::setUp();
31 $this->serializer = $this->container->get('serializer');
32 }
33
34 /**
35 * Confirms that modules can register normalizers and encoders.
36 */
37 public function testSerializerComponentRegistration() {
38 $object = new \stdClass();
39 $format = 'serialization_test';
40 $expected = 'Normalized by SerializationTestNormalizer, Encoded by SerializationTestEncoder';
41
42 // Ensure the serialization invokes the expected normalizer and encoder.
43 $this->assertIdentical($this->serializer->serialize($object, $format), $expected);
44
45 // Ensure the serialization fails for an unsupported format.
46 try {
47 $this->serializer->serialize($object, 'unsupported_format');
48 $this->fail('The serializer was expected to throw an exception for an unsupported format, but did not.');
49 }
50 catch (UnexpectedValueException $e) {
51 $this->pass('The serializer threw an exception for an unsupported format.');
52 }
53 }
54
55 }