YamlTest.php in Drupal 10
File
core/tests/Drupal/Tests/Core/Serialization/YamlTest.php
View source
<?php
namespace Drupal\Tests\Core\Serialization;
use Drupal\Component\Serialization\SerializationInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;
class YamlTest extends UnitTestCase {
public function testGetSerialization() {
new Settings([
'yaml_parser_class' => YamlParserProxy::class,
]);
$this
->assertEquals(YamlParserProxy::class, Settings::get('yaml_parser_class'));
$mock = $this
->getMockBuilder('\\stdClass')
->addMethods([
'encode',
'decode',
'getFileExtension',
])
->getMock();
$mock
->expects($this
->once())
->method('decode');
YamlParserProxy::setMock($mock);
Yaml::decode('---');
new Settings([]);
}
}
class YamlParserProxy implements SerializationInterface {
protected static $mock;
public static function setMock($mock) {
static::$mock = $mock;
}
public static function encode($data) {
return static::$mock
->encode($data);
}
public static function decode($raw) {
return static::$mock
->decode($raw);
}
public static function getFileExtension() {
return static::$mock
->getFileExtension();
}
}