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\Normalizer;
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;
19 class CustomNormalizerTest extends TestCase
22 * @var CustomNormalizer
26 protected function setUp()
28 $this->normalizer = new CustomNormalizer();
29 $this->normalizer->setSerializer(new Serializer());
32 public function testInterface()
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);
39 public function testSerialize()
41 $obj = new ScalarDummy();
44 $this->assertEquals('foo', $this->normalizer->normalize($obj, 'json'));
45 $this->assertEquals('xml', $this->normalizer->normalize($obj, 'xml'));
48 public function testDeserialize()
50 $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'xml');
51 $this->assertEquals('foo', $obj->xmlFoo);
52 $this->assertNull($obj->foo);
54 $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'json');
55 $this->assertEquals('foo', $obj->foo);
56 $this->assertNull($obj->xmlFoo);
59 public function testSupportsNormalization()
61 $this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
62 $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
65 public function testSupportsDenormalization()
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'));