comparison core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\Component\Serialization;
4
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Drupal\Component\Serialization\YamlSymfony;
7
8 /**
9 * Tests the YamlSymfony serialization implementation.
10 *
11 * @group Drupal
12 * @group Serialization
13 * @coversDefaultClass \Drupal\Component\Serialization\YamlSymfony
14 */
15 class YamlSymfonyTest extends YamlTestBase {
16
17 /**
18 * Tests encoding and decoding basic data structures.
19 *
20 * @covers ::encode
21 * @covers ::decode
22 * @dataProvider providerEncodeDecodeTests
23 */
24 public function testEncodeDecode($data) {
25 $this->assertEquals($data, YamlSymfony::decode(YamlSymfony::encode($data)));
26 }
27
28 /**
29 * Tests decoding YAML node anchors.
30 *
31 * @covers ::decode
32 * @dataProvider providerDecodeTests
33 */
34 public function testDecode($string, $data) {
35 $this->assertEquals($data, YamlSymfony::decode($string));
36 }
37
38 /**
39 * Tests our encode settings.
40 *
41 * @covers ::encode
42 */
43 public function testEncode() {
44 $this->assertEquals('foo:
45 bar: \'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis\'
46 ', YamlSymfony::encode(['foo' => ['bar' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis']]));
47 }
48
49 /**
50 * @covers ::getFileExtension
51 */
52 public function testGetFileExtension() {
53 $this->assertEquals('yml', YamlSymfony::getFileExtension());
54 }
55
56 /**
57 * Tests that invalid YAML throws an exception.
58 *
59 * @covers ::decode
60 */
61 public function testError() {
62 $this->setExpectedException(InvalidDataTypeException::class);
63 YamlSymfony::decode('foo: [ads');
64 }
65
66 /**
67 * Ensures that php object support is disabled.
68 *
69 * @covers ::encode
70 */
71 public function testObjectSupportDisabled() {
72 $this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
73 $object = new \stdClass();
74 $object->foo = 'bar';
75 YamlSymfony::encode([$object]);
76 }
77
78 }