a3c3c1a0e62eca516c9c67ff3ef907b46dc9878f
[yaffs-website] / vendor / symfony / serializer / Tests / Normalizer / CustomNormalizerTest.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\Normalizer;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy;
16 use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
17 use Symfony\Component\Serializer\Serializer;
18
19 class CustomNormalizerTest extends TestCase
20 {
21     /**
22      * @var CustomNormalizer
23      */
24     private $normalizer;
25
26     protected function setUp()
27     {
28         $this->normalizer = new CustomNormalizer();
29         $this->normalizer->setSerializer(new Serializer());
30     }
31
32     public function testInterface()
33     {
34         $this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\NormalizerInterface', $this->normalizer);
35         $this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\DenormalizerInterface', $this->normalizer);
36         $this->assertInstanceOf('Symfony\Component\Serializer\SerializerAwareInterface', $this->normalizer);
37     }
38
39     public function testSerialize()
40     {
41         $obj = new ScalarDummy();
42         $obj->foo = 'foo';
43         $obj->xmlFoo = 'xml';
44         $this->assertEquals('foo', $this->normalizer->normalize($obj, 'json'));
45         $this->assertEquals('xml', $this->normalizer->normalize($obj, 'xml'));
46     }
47
48     public function testDeserialize()
49     {
50         $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'xml');
51         $this->assertEquals('foo', $obj->xmlFoo);
52         $this->assertNull($obj->foo);
53
54         $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'json');
55         $this->assertEquals('foo', $obj->foo);
56         $this->assertNull($obj->xmlFoo);
57     }
58
59     public function testSupportsNormalization()
60     {
61         $this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
62         $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
63     }
64
65     public function testSupportsDenormalization()
66     {
67         $this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy'));
68         $this->assertFalse($this->normalizer->supportsDenormalization(array(), 'stdClass'));
69         $this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\DenormalizableDummy'));
70     }
71 }