10ebc2f9f2c737650a737c8c57a793c84b1e888b
[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     }
37
38     public function testSerialize()
39     {
40         $obj = new ScalarDummy();
41         $obj->foo = 'foo';
42         $obj->xmlFoo = 'xml';
43         $this->assertEquals('foo', $this->normalizer->normalize($obj, 'json'));
44         $this->assertEquals('xml', $this->normalizer->normalize($obj, 'xml'));
45     }
46
47     public function testDeserialize()
48     {
49         $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'xml');
50         $this->assertEquals('foo', $obj->xmlFoo);
51         $this->assertNull($obj->foo);
52
53         $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'json');
54         $this->assertEquals('foo', $obj->foo);
55         $this->assertNull($obj->xmlFoo);
56     }
57
58     public function testSupportsNormalization()
59     {
60         $this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
61         $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
62     }
63
64     public function testSupportsDenormalization()
65     {
66         $this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy'));
67         $this->assertFalse($this->normalizer->supportsDenormalization(array(), 'stdClass'));
68         $this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\DenormalizableDummy'));
69     }
70 }