* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Tests\Normalizer; use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\Tests\Fixtures\JsonSerializableDummy; /** * @author Fred Cox */ class JsonSerializableNormalizerTest extends TestCase { /** * @var JsonSerializableNormalizer */ private $normalizer; /** * @var \PHPUnit_Framework_MockObject_MockObject|SerializerInterface */ private $serializer; protected function setUp() { $this->serializer = $this->getMockBuilder(JsonSerializerNormalizer::class)->getMock(); $this->normalizer = new JsonSerializableNormalizer(); $this->normalizer->setSerializer($this->serializer); } public function testSupportNormalization() { $this->assertTrue($this->normalizer->supportsNormalization(new JsonSerializableDummy())); $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass())); } public function testNormalize() { $this->serializer ->expects($this->once()) ->method('normalize') ->will($this->returnCallback(function ($data) { $this->assertArraySubset(array('foo' => 'a', 'bar' => 'b', 'baz' => 'c'), $data); return 'string_object'; })) ; $this->assertEquals('string_object', $this->normalizer->normalize(new JsonSerializableDummy())); } /** * @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException */ public function testCircularNormalize() { $this->normalizer->setCircularReferenceLimit(1); $this->serializer ->expects($this->once()) ->method('normalize') ->will($this->returnCallback(function ($data, $format, $context) { $this->normalizer->normalize($data['qux'], $format, $context); return 'string_object'; })) ; $this->assertEquals('string_object', $this->normalizer->normalize(new JsonSerializableDummy())); } /** * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException * @expectedExceptionMessage The object must implement "JsonSerializable". */ public function testInvalidDataThrowException() { $this->normalizer->normalize(new \stdClass()); } } abstract class JsonSerializerNormalizer implements SerializerInterface, NormalizerInterface { } __halt_compiler();----SIGNATURE:----X6lRAgPzRRUQuxqXcJps4x11g8ZByykplw2IL9vvevTlB1egOGAjK1k2ZhTc9nCIPIPTDM55vauamvw22iEgcFkSxKx4Vwqoc2ccu3hrcwNVzL3nb7ddu9aH0yQKDH/0cgKxt4SVhfYEHWFhzU3HniCKc62ik8nKHcpgVM1AhFyoYvXo0GLiXQ92KXXGDXkmGnWRhMf55wusDIPitr8YnSmRnIZRTnfvW5GvYnTZiIsoTYv+92UaIk8qcnzfEtZWWmt7+bl/oRm9VC0TUB9gz8hHyhuulM9kzOSJ4HkfDZLC3v0LDSsHbE5y/PuPhoE+SPmC//HYwDpISh0ZogTqC45Bht6G5MD7t6gnIdqepOjx/r1+3bUziEGrIshRv1SrGgpdVdavNjInP/+8aoFThHehX27t4+Y7xlw0wgVofNu1gxxubqEZ2OhAeFZ8mQ/Ol576y36WF4EpAE8ISsQ5ctJneXu6fv65niP1JdF0JzFxxPVA6ac6oJgWHO3VRQgFOsk60FkOK+Ik3hgGlds71eCn4/VjBK6sB2XS7rYWx+EAdm935MXYNmBGz7UhHHfy5gAIdGMFsATI7ldnSbPJsJ7QNGA2tGpbZXUuQjJM5kYCyROOQOQf3WOhdwQdbuz0HTafPYB/ZaMi+c6oMVAAkyla8QzxrkDACfbHOl9Maug=----ATTACHMENT:----Nzk1NjU2MjUyNjA1Mjg5OSAzOTM1NTE0NzYxMTc3NyA4NzU2MzcwMDM3MTIzNjE2