* * 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:----hXW1hsr7KJfsMgMcxGDvLyYX3KxfoIaQwttBZqrdavq2sLq2a4YNVU+s8PLw4E6iRwkPG47KZfj+exV5kpnzqaZje9GCfLR8U4h4uXJuzlaQ05XPAFKVZa2LcbCafxBAisT3tMPv8w16sgbvDFmh9YCBKBbPX4hrg1BsrOGX+x7LRBOx+SPN/H67SoG03gM2hs1Yn9TNCyuBFTSpfwh9KJTAcTZqWp288es8NCbJluo6ToxuLwt+b7WvNEcm48cfivlBRE23L83VULMwZF9gsOuhguCp1UE1wcGJbpvY/xnyXNcARkgtQr7Y1ELlUttAgtKMr2Lk0W3ROBtGJ6L6SIewZ1dMpNpv61k57xVJVCxKCouLKAObRkOQ0ZA495MY3tU7mNn4RQbRSBCRU719jSxaOKK+Ig8FuR7Uvc/Lj11HOGdGcTqCDS9/9DenN0v2kKHgkgc/eUzECv+nBYzGFX+ELnSTiXIXLYHejxhkeCbI+trevdI4PNrMKJyg4mu7i3kZjpSPjfFIG+uc60npXgop+nAeTAWx20JQdiL8xl0KSYlCshdBnE4ybXqFTprCLIAaN8/yYVJ7G9AXD1zhT3tZXc314GyGcbhcXO7/xs2ZflWc0EiirzCOZRFZaLga+5pBn348j40J4HYNeTyI7+nKWOtLsqF7PsXPJF77wwA=----ATTACHMENT:----OTY4NTkwMjY2MjE3Nzg1NyA0MjE5NTE2MjM2NDgxMjI3IDY2OTMwNzk0OTQ5Mzk3Nzg=