* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Tests\Encoder; use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Encoder\YamlEncoder; use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Yaml; /** * @author Kévin Dunglas */ class YamlEncoderTest extends TestCase { public function testEncode() { $encoder = new YamlEncoder(); $this->assertEquals('foo', $encoder->encode('foo', 'yaml')); $this->assertEquals('{ foo: 1 }', $encoder->encode(array('foo' => 1), 'yaml')); } public function testSupportsEncoding() { $encoder = new YamlEncoder(); $this->assertTrue($encoder->supportsEncoding('yaml')); $this->assertFalse($encoder->supportsEncoding('json')); } public function testDecode() { $encoder = new YamlEncoder(); $this->assertEquals('foo', $encoder->decode('foo', 'yaml')); $this->assertEquals(array('foo' => 1), $encoder->decode('{ foo: 1 }', 'yaml')); } public function testSupportsDecoding() { $encoder = new YamlEncoder(); $this->assertTrue($encoder->supportsDecoding('yaml')); $this->assertFalse($encoder->supportsDecoding('json')); } public function testContext() { $encoder = new YamlEncoder(new Dumper(), new Parser(), array('yaml_inline' => 1, 'yaml_indent' => 4, '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(array('foo' => $obj), 'yaml'), $this->logicalOr($this->equalTo($legacyTag), $this->equalTo($spacedTag))); $this->assertEquals(' { foo: null }', $encoder->encode(array('foo' => $obj), 'yaml', array('yaml_inline' => 0, 'yaml_indent' => 2, 'yaml_flags' => 0))); $this->assertEquals(array('foo' => $obj), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml')); $this->assertEquals(array('foo' => null), $encoder->decode("foo: !php/object 'O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}'", 'yaml', array('yaml_flags' => 0))); } } __halt_compiler();----SIGNATURE:----MwDIUdiOL4nJDFG+HEyMYDRST5TfCB4s7PSZFAcWo+XiWOZKqmqzc4acNcjTpwQHvW9OkF4CVMq18k6C824fs9r3Wh6BnAeem7YjBRbRySeUWLakeFNSNwUfm4Y4IqhN9NioG/vmsYmkr9YAeS2agg2dERqsYLcuYmPl/XLqe6uNHo2bGj8DdwlbdTbPOAsPn62AyPBSsmDGDOIliLJ+SQbFptD3d1ljqmgYJNndBZcBG9BFy5fW41C02AOI+VisXGO7W0s4J8P4emJBz1tTvu781DFy7qlz2lbIy1iMLxdsTlp71ZmczTr0Dn2bkd/UGAPdlD8jIt3vXtuvL908ULGUmnT/t6MSxtRsWAuzuVjigz/I0Fd12mJPAsqr3fVwTrcJB4Ehm+V7DxdzOZZlZ9gb5GX6+Ihxymf0yMoFzAYKgbV3kd4v/FfI2ziuG4ZD7XPNll9GfaJpWXxEq9JMD2Apn0+7/xuspj76mhfjFJJy5aKQ30Ok3BTVrs/CuuFoK6HkDZtg+UK6bbNcS/KHGdx6Uj7Uf8hNN6ej1CtF5CXN/R8qAT+DLCDL8EC2LtYEiUXO7PuxccTum68blwbRb+f5bWasQMjJemFyB0wU6kZuh5FCrgSDM4ESmjfUH90Awgqtxv8HG43R7hiPBkW++JZ9r4qzJp46gdScJfIbngY=----ATTACHMENT:----MzMxNzU3ODYxMjI0Mjg4IDI0NzUxODY4OTI5NzQ1MCA1MDc4MDQzNDU5ODI5ODU3