YamlPeclTest.php in Drupal 9
File
core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
View source
<?php
namespace Drupal\Tests\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Component\Serialization\YamlPecl;
class YamlPeclTest extends YamlTestBase {
public function testEncodeDecode($data) {
$this
->assertEquals($data, YamlPecl::decode(YamlPecl::encode($data)));
}
public function testObjectSupportDisabled() {
$object = new \stdClass();
$object->foo = 'bar';
$this
->assertEquals([
'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}',
], YamlPecl::decode(YamlPecl::encode([
$object,
])));
$this
->assertEquals(0, ini_get('yaml.decode_php'));
}
public function testDecode($string, $data) {
$this
->assertEquals($data, YamlPecl::decode($string));
}
public function testEncode() {
$this
->assertEquals('---
foo:
bar: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis
...
', YamlPecl::encode([
'foo' => [
'bar' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis',
],
]));
}
public function testApplyBooleanCallbacks($string, $expected) {
$this
->assertEquals($expected, YamlPecl::applyBooleanCallbacks($string, 'bool', NULL));
}
public function testGetFileExtension() {
$this
->assertEquals('yml', YamlPecl::getFileExtension());
}
public function testError() {
$this
->expectException(InvalidDataTypeException::class);
YamlPecl::decode('foo: [ads');
}
}