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);
38 public function testSerialize()
40 $obj = new ScalarDummy();
43 $this->assertEquals('foo', $this->normalizer->normalize($obj, 'json'));
44 $this->assertEquals('xml', $this->normalizer->normalize($obj, 'xml'));
47 public function testDeserialize()
49 $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'xml');
50 $this->assertEquals('foo', $obj->xmlFoo);
51 $this->assertNull($obj->foo);
53 $obj = $this->normalizer->denormalize('foo', get_class(new ScalarDummy()), 'json');
54 $this->assertEquals('foo', $obj->foo);
55 $this->assertNull($obj->xmlFoo);
58 public function testSupportsNormalization()
60 $this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
61 $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
64 public function testSupportsDenormalization()
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'));