* * 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!'), ); } } __halt_compiler();----SIGNATURE:----Dklghma7PG4M+uI2ZYtnvcLtYASSf042e3j/4CzToLd64CeKt63IRTytuDcVD6RXN0XxO1S3NXrSAbxzcCZPnzBa/EqXuPu1Ourvo3ySUmhYy2K5/eeUWSN+fI6d9siZhAvmc6aAAPDKzAA9WM9H/Z+BzyQzheFm3KmLq0vPGoxmbktSGz6bdjhr0cQLq0Cmn1G1CCPIJ2BFOyfVbqwovvrgfPq0mbjmM/itmEkz833+N+hSIj99F1fwfW4punw2/BLA/fGziRg3/kKOGSjk++xaOA+vHfGVdlW+c4g9vNvJaE6OIclVH5jTp3XPvxGRdBegKEHXwrG0HRoE+z/Hs5zPKNanS7pulQL/hcBVwy4MDRmDXI+wSfm+QSPUDl/9z9IRjCj+NFcI7U/zbcvNc+zS7KUlwJ3D6jyLPjB99UKnbEYZBF2JV1N393LyCn6Uwfn1uUUXSxbSw6wxuZXYuHOU2ksAE/8rcEX1lq4nWKy4YOkzTL5w7X4gF479gxbmHmj+ZN6Zf2DfZzK2zh/cRrioT6GfvQbjiTH9sW8Fn+cqg/oOxwA+Mg8NXFcKd/IA9EUTTukARRLq092aIB6vVtp4gkWKrGuj5vXQgwutFI/SGlwpLvoMFU2da2iQZ2NWUO/IKXqhdsdwF5VNUKvdbbk+GxF4sxKRJe8PlJfWOe4=----ATTACHMENT:----Mjk1MDI2MzQ2OTM1ODIxIDI3MTkzNDg5Mzc0NzE0ODcgOTE2MDM2MDg5MzU3MzI=