More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Serialization / YamlTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Serialization;
4
5 use Drupal\Component\Serialization\SerializationInterface;
6 use Drupal\Core\Serialization\Yaml;
7 use Drupal\Core\Site\Settings;
8 use Drupal\Tests\UnitTestCase;
9
10 /**
11  * @coversDefaultClass \Drupal\Core\Serialization\Yaml
12  * @group Serialization
13  */
14 class YamlTest extends UnitTestCase {
15
16   /**
17    * Test that the overridden serializer is called.
18    *
19    * @covers ::getSerializer
20    * @runInSeparateProcess
21    */
22   public function testGetSeralization() {
23     new Settings(['yaml_parser_class' => YamlParserProxy::class]);
24
25     $this->assertEquals(YamlParserProxy::class, Settings::get('yaml_parser_class'));
26
27     $mock = $this->getMockBuilder('\stdClass')
28       ->setMethods(['encode', 'decode', 'getFileExtension'])
29       ->getMock();
30     $mock
31       ->expects($this->once())
32       ->method('decode');
33     YamlParserProxy::setMock($mock);
34     Yaml::decode('---');
35
36     new Settings([]);
37   }
38
39 }
40
41 class YamlParserProxy implements SerializationInterface {
42
43   /**
44    * @var \Drupal\Component\Serialization\SerializationInterface
45    */
46   protected static $mock;
47
48   public static function setMock($mock) {
49     static::$mock = $mock;
50   }
51
52   public static function encode($data) {
53     return static::$mock->encode($data);
54   }
55
56   public static function decode($raw) {
57     return static::$mock->decode($raw);
58   }
59
60   public static function getFileExtension() {
61     return static::$mock->getFileExtension();
62   }
63
64 }