ed33233fb47ea4686212e534eab7d65fef389740
[yaffs-website] / vendor / symfony / serializer / Tests / Encoder / JsonEncodeTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Serializer\Tests\Encoder;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Encoder\JsonEncode;
16 use Symfony\Component\Serializer\Encoder\JsonEncoder;
17
18 class JsonEncodeTest extends TestCase
19 {
20     private $encoder;
21
22     protected function setUp()
23     {
24         $this->encode = new JsonEncode();
25     }
26
27     public function testSupportsEncoding()
28     {
29         $this->assertTrue($this->encode->supportsEncoding(JsonEncoder::FORMAT));
30         $this->assertFalse($this->encode->supportsEncoding('foobar'));
31     }
32
33     /**
34      * @dataProvider encodeProvider
35      */
36     public function testEncode($toEncode, $expected, $context)
37     {
38         $this->assertEquals(
39             $expected,
40             $this->encode->encode($toEncode, JsonEncoder::FORMAT, $context)
41         );
42     }
43
44     public function encodeProvider()
45     {
46         return array(
47             array(array(), '[]', array()),
48             array(array(), '{}', array('json_encode_options' => JSON_FORCE_OBJECT)),
49         );
50     }
51
52     /**
53      * @requires function json_last_error_msg
54      * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
55      */
56     public function testEncodeWithError()
57     {
58         $this->encode->encode("\xB1\x31", JsonEncoder::FORMAT);
59     }
60 }