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\JsonEncode;
16 use Symfony\Component\Serializer\Encoder\JsonEncoder;
18 class JsonEncodeTest extends TestCase
22 protected function setUp()
24 $this->encode = new JsonEncode();
27 public function testSupportsEncoding()
29 $this->assertTrue($this->encode->supportsEncoding(JsonEncoder::FORMAT));
30 $this->assertFalse($this->encode->supportsEncoding('foobar'));
34 * @dataProvider encodeProvider
36 public function testEncode($toEncode, $expected, $context)
40 $this->encode->encode($toEncode, JsonEncoder::FORMAT, $context)
44 public function encodeProvider()
47 array(array(), '[]', array()),
48 array(array(), '{}', array('json_encode_options' => JSON_FORCE_OBJECT)),
53 * @requires function json_last_error_msg
54 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
56 public function testEncodeWithError()
58 $this->encode->encode("\xB1\x31", JsonEncoder::FORMAT);