X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fserializer%2FTests%2FEncoder%2FYamlEncoderTest.php;fp=vendor%2Fsymfony%2Fserializer%2FTests%2FEncoder%2FYamlEncoderTest.php;h=c60203966739495ab380845e611f8395942f4d5f;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/symfony/serializer/Tests/Encoder/YamlEncoderTest.php b/vendor/symfony/serializer/Tests/Encoder/YamlEncoderTest.php new file mode 100644 index 000000000..c60203966 --- /dev/null +++ b/vendor/symfony/serializer/Tests/Encoder/YamlEncoderTest.php @@ -0,0 +1,69 @@ + + * + * 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; + + $this->assertEquals(" foo: !php/object:O:8:\"stdClass\":1:{s:3:\"bar\";i:2;}\n", $encoder->encode(array('foo' => $obj), 'yaml')); + $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))); + } +}