public function testContext() { $encoder =
new YamlEncoder(null, null,
[YamlEncoder::YAML_INLINE => 1, YamlEncoder::YAML_INDENT => 4, YamlEncoder::YAML_FLAGS => Yaml::DUMP_OBJECT | Yaml::PARSE_OBJECT
]);
$obj =
new \
stdClass();
$obj->bar = 2;
$legacyTag = " foo: !php/object:O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}\n";
$spacedTag = " foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'\n";
$this->
assertThat($encoder->
encode(['foo' =>
$obj], 'yaml'
),
$this->
logicalOr($this->
equalTo($legacyTag),
$this->
equalTo($spacedTag)));
$this->
assertEquals(' { foo: null }',
$encoder->
encode(['foo' =>
$obj], 'yaml',
[YamlEncoder::YAML_INLINE => 0, YamlEncoder::YAML_INDENT => 2, YamlEncoder::YAML_FLAGS => 0
]));
$this->
assertEquals(['foo' =>
$obj],
$encoder->
decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml'
));
$this->
assertEquals(['foo' => null
],
$encoder->
decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml',
[YamlEncoder::YAML_FLAGS => 0
]));
}}