X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fserializer%2FTests%2FEncoder%2FJsonDecodeTest.php;fp=vendor%2Fsymfony%2Fserializer%2FTests%2FEncoder%2FJsonDecodeTest.php;h=774064d43a8537ed85b8fcf4b27197d0bb3e2150;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/symfony/serializer/Tests/Encoder/JsonDecodeTest.php b/vendor/symfony/serializer/Tests/Encoder/JsonDecodeTest.php new file mode 100644 index 000000000..774064d43 --- /dev/null +++ b/vendor/symfony/serializer/Tests/Encoder/JsonDecodeTest.php @@ -0,0 +1,75 @@ + + * + * 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\JsonDecode; +use Symfony\Component\Serializer\Encoder\JsonEncoder; + +class JsonDecodeTest extends TestCase +{ + /** @var \Symfony\Component\Serializer\Encoder\JsonDecode */ + private $decode; + + protected function setUp() + { + $this->decode = new JsonDecode(); + } + + public function testSupportsDecoding() + { + $this->assertTrue($this->decode->supportsDecoding(JsonEncoder::FORMAT)); + $this->assertFalse($this->decode->supportsDecoding('foobar')); + } + + /** + * @dataProvider decodeProvider + */ + public function testDecode($toDecode, $expected, $context) + { + $this->assertEquals( + $expected, + $this->decode->decode($toDecode, JsonEncoder::FORMAT, $context) + ); + } + + public function decodeProvider() + { + $stdClass = new \stdClass(); + $stdClass->foo = 'bar'; + + $assoc = array('foo' => 'bar'); + + return array( + array('{"foo": "bar"}', $stdClass, array()), + array('{"foo": "bar"}', $assoc, array('json_decode_associative' => true)), + ); + } + + /** + * @requires function json_last_error_msg + * @dataProvider decodeProviderException + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + */ + public function testDecodeWithException($value) + { + $this->decode->decode($value, JsonEncoder::FORMAT); + } + + public function decodeProviderException() + { + return array( + array("{'foo': 'bar'}"), + array('kaboom!'), + ); + } +}