Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / serializer / Tests / Encoder / JsonDecodeTest.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\JsonDecode;
16 use Symfony\Component\Serializer\Encoder\JsonEncoder;
17
18 class JsonDecodeTest extends TestCase
19 {
20     /** @var \Symfony\Component\Serializer\Encoder\JsonDecode */
21     private $decode;
22
23     protected function setUp()
24     {
25         $this->decode = new JsonDecode();
26     }
27
28     public function testSupportsDecoding()
29     {
30         $this->assertTrue($this->decode->supportsDecoding(JsonEncoder::FORMAT));
31         $this->assertFalse($this->decode->supportsDecoding('foobar'));
32     }
33
34     /**
35      * @dataProvider decodeProvider
36      */
37     public function testDecode($toDecode, $expected, $context)
38     {
39         $this->assertEquals(
40             $expected,
41             $this->decode->decode($toDecode, JsonEncoder::FORMAT, $context)
42         );
43     }
44
45     public function decodeProvider()
46     {
47         $stdClass = new \stdClass();
48         $stdClass->foo = 'bar';
49
50         $assoc = array('foo' => 'bar');
51
52         return array(
53             array('{"foo": "bar"}', $stdClass, array()),
54             array('{"foo": "bar"}', $assoc, array('json_decode_associative' => true)),
55         );
56     }
57
58     /**
59      * @requires function json_last_error_msg
60      * @dataProvider decodeProviderException
61      * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
62      */
63     public function testDecodeWithException($value)
64     {
65         $this->decode->decode($value, JsonEncoder::FORMAT);
66     }
67
68     public function decodeProviderException()
69     {
70         return array(
71             array("{'foo': 'bar'}"),
72             array('kaboom!'),
73         );
74     }
75 }