4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Tests\Encoder;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Encoder\JsonDecode;
16 use Symfony\Component\Serializer\Encoder\JsonEncoder;
18 class JsonDecodeTest extends TestCase
20 /** @var \Symfony\Component\Serializer\Encoder\JsonDecode */
23 protected function setUp()
25 $this->decode = new JsonDecode();
28 public function testSupportsDecoding()
30 $this->assertTrue($this->decode->supportsDecoding(JsonEncoder::FORMAT));
31 $this->assertFalse($this->decode->supportsDecoding('foobar'));
35 * @dataProvider decodeProvider
37 public function testDecode($toDecode, $expected, $context)
41 $this->decode->decode($toDecode, JsonEncoder::FORMAT, $context)
45 public function decodeProvider()
47 $stdClass = new \stdClass();
48 $stdClass->foo = 'bar';
50 $assoc = array('foo' => 'bar');
53 array('{"foo": "bar"}', $stdClass, array()),
54 array('{"foo": "bar"}', $assoc, array('json_decode_associative' => true)),
59 * @requires function json_last_error_msg
60 * @dataProvider decodeProviderException
61 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
63 public function testDecodeWithException($value)
65 $this->decode->decode($value, JsonEncoder::FORMAT);
68 public function decodeProviderException()
71 array("{'foo': 'bar'}"),