Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,131 @@
<?php
namespace Symfony\Component\Serializer\Tests\Normalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractNormalizerDummy;
use Symfony\Component\Serializer\Tests\Fixtures\NullableConstructorArgumentDummy;
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;
use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorDummy;
use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorNormalizer;
/**
* Provides a dummy Normalizer which extends the AbstractNormalizer.
*
* @author Konstantin S. M. Möllers <ksm.moellers@gmail.com>
*/
class AbstractNormalizerTest extends TestCase
{
/**
* @var AbstractNormalizerDummy
*/
private $normalizer;
/**
* @var ClassMetadataFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $classMetadata;
protected function setUp()
{
$loader = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\Loader\LoaderChain')->setConstructorArgs(array(array()))->getMock();
$this->classMetadata = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory')->setConstructorArgs(array($loader))->getMock();
$this->normalizer = new AbstractNormalizerDummy($this->classMetadata);
}
public function testGetAllowedAttributesAsString()
{
$classMetadata = new ClassMetadata('c');
$a1 = new AttributeMetadata('a1');
$classMetadata->addAttributeMetadata($a1);
$a2 = new AttributeMetadata('a2');
$a2->addGroup('test');
$classMetadata->addAttributeMetadata($a2);
$a3 = new AttributeMetadata('a3');
$a3->addGroup('other');
$classMetadata->addAttributeMetadata($a3);
$a4 = new AttributeMetadata('a4');
$a4->addGroup('test');
$a4->addGroup('other');
$classMetadata->addAttributeMetadata($a4);
$this->classMetadata->method('getMetadataFor')->willReturn($classMetadata);
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('test')), true);
$this->assertEquals(array('a2', 'a4'), $result);
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('other')), true);
$this->assertEquals(array('a3', 'a4'), $result);
}
public function testGetAllowedAttributesAsObjects()
{
$classMetadata = new ClassMetadata('c');
$a1 = new AttributeMetadata('a1');
$classMetadata->addAttributeMetadata($a1);
$a2 = new AttributeMetadata('a2');
$a2->addGroup('test');
$classMetadata->addAttributeMetadata($a2);
$a3 = new AttributeMetadata('a3');
$a3->addGroup('other');
$classMetadata->addAttributeMetadata($a3);
$a4 = new AttributeMetadata('a4');
$a4->addGroup('test');
$a4->addGroup('other');
$classMetadata->addAttributeMetadata($a4);
$this->classMetadata->method('getMetadataFor')->willReturn($classMetadata);
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('test')), false);
$this->assertEquals(array($a2, $a4), $result);
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('other')), false);
$this->assertEquals(array($a3, $a4), $result);
}
public function testObjectToPopulateWithProxy()
{
$proxyDummy = new ProxyDummy();
$context = array(AbstractNormalizer::OBJECT_TO_POPULATE => $proxyDummy);
$normalizer = new ObjectNormalizer();
$normalizer->denormalize(array('foo' => 'bar'), 'Symfony\Component\Serializer\Tests\Fixtures\ToBeProxyfiedDummy', null, $context);
$this->assertSame('bar', $proxyDummy->getFoo());
}
public function testObjectWithStaticConstructor()
{
$normalizer = new StaticConstructorNormalizer();
$dummy = $normalizer->denormalize(array('foo' => 'baz'), StaticConstructorDummy::class);
$this->assertInstanceOf(StaticConstructorDummy::class, $dummy);
$this->assertEquals('baz', $dummy->quz);
$this->assertNull($dummy->foo);
}
/**
* @requires PHP 7.1
*/
public function testObjectWithNullableConstructorArgument()
{
$normalizer = new ObjectNormalizer();
$dummy = $normalizer->denormalize(array('foo' => null), NullableConstructorArgumentDummy::class);
$this->assertNull($dummy->getFoo());
}
}

View file

@ -0,0 +1,340 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerInterface;
class AbstractObjectNormalizerTest extends TestCase
{
public function testDenormalize()
{
$normalizer = new AbstractObjectNormalizerDummy();
$normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy');
$this->assertSame('foo', $normalizedData->foo);
$this->assertNull($normalizedData->bar);
$this->assertSame('baz', $normalizedData->baz);
}
public function testInstantiateObjectDenormalizer()
{
$data = array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz');
$class = __NAMESPACE__.'\Dummy';
$context = array();
$normalizer = new AbstractObjectNormalizerDummy();
$this->assertInstanceOf(__NAMESPACE__.'\Dummy', $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), array()));
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\ExtraAttributesException
* @expectedExceptionMessage Extra attributes are not allowed ("fooFoo", "fooBar" are unknown).
*/
public function testDenormalizeWithExtraAttributes()
{
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$normalizer = new AbstractObjectNormalizerDummy($factory);
$normalizer->denormalize(
array('fooFoo' => 'foo', 'fooBar' => 'bar'),
__NAMESPACE__.'\Dummy',
'any',
array('allow_extra_attributes' => false)
);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\ExtraAttributesException
* @expectedExceptionMessage Extra attributes are not allowed ("fooFoo", "fooBar" are unknown).
*/
public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory()
{
$normalizer = new AbstractObjectNormalizerWithMetadata();
$normalizer->denormalize(
array('fooFoo' => 'foo', 'fooBar' => 'bar', 'bar' => 'bar'),
Dummy::class,
'any',
array('allow_extra_attributes' => false)
);
}
public function testDenormalizeCollectionDecodedFromXmlWithOneChild()
{
$denormalizer = $this->getDenormalizerForDummyCollection();
$dummyCollection = $denormalizer->denormalize(
array(
'children' => array(
'bar' => 'first',
),
),
DummyCollection::class,
'xml'
);
$this->assertInstanceOf(DummyCollection::class, $dummyCollection);
$this->assertInternalType('array', $dummyCollection->children);
$this->assertCount(1, $dummyCollection->children);
$this->assertInstanceOf(DummyChild::class, $dummyCollection->children[0]);
}
public function testDenormalizeCollectionDecodedFromXmlWithTwoChildren()
{
$denormalizer = $this->getDenormalizerForDummyCollection();
$dummyCollection = $denormalizer->denormalize(
array(
'children' => array(
array('bar' => 'first'),
array('bar' => 'second'),
),
),
DummyCollection::class,
'xml'
);
$this->assertInstanceOf(DummyCollection::class, $dummyCollection);
$this->assertInternalType('array', $dummyCollection->children);
$this->assertCount(2, $dummyCollection->children);
$this->assertInstanceOf(DummyChild::class, $dummyCollection->children[0]);
$this->assertInstanceOf(DummyChild::class, $dummyCollection->children[1]);
}
private function getDenormalizerForDummyCollection()
{
$extractor = $this->getMockBuilder(PhpDocExtractor::class)->getMock();
$extractor->method('getTypes')
->will($this->onConsecutiveCalls(
array(
new Type(
'array',
false,
null,
true,
new Type('int'),
new Type('object', false, DummyChild::class)
),
),
null
));
$denormalizer = new AbstractObjectNormalizerCollectionDummy(null, null, $extractor);
$arrayDenormalizer = new ArrayDenormalizerDummy();
$serializer = new SerializerCollectionDummy(array($arrayDenormalizer, $denormalizer));
$arrayDenormalizer->setSerializer($serializer);
$denormalizer->setSerializer($serializer);
return $denormalizer;
}
/**
* Test that additional attributes throw an exception if no metadata factory is specified.
*
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
* @expectedExceptionMessage A class metadata factory must be provided in the constructor when setting "allow_extra_attributes" to false.
*/
public function testExtraAttributesException()
{
$normalizer = new ObjectNormalizer();
$normalizer->denormalize(array(), \stdClass::class, 'xml', array(
'allow_extra_attributes' => false,
));
}
}
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
{
protected function extractAttributes($object, $format = null, array $context = array())
{
}
protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
{
}
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
{
$object->$attribute = $value;
}
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
{
return \in_array($attribute, array('foo', 'baz'));
}
public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, $format = null)
{
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
}
}
class Dummy
{
public $foo;
public $bar;
public $baz;
}
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
{
public function __construct()
{
parent::__construct(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())));
}
protected function extractAttributes($object, $format = null, array $context = array())
{
}
protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
{
}
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
{
$object->$attribute = $value;
}
}
class DummyCollection
{
/** @var DummyChild[] */
public $children;
}
class DummyChild
{
public $bar;
}
class SerializerCollectionDummy implements SerializerInterface, DenormalizerInterface
{
private $normalizers;
/**
* @param DenormalizerInterface[] $normalizers
*/
public function __construct($normalizers)
{
$this->normalizers = $normalizers;
}
public function serialize($data, $format, array $context = array())
{
}
public function deserialize($data, $type, $format, array $context = array())
{
}
public function denormalize($data, $type, $format = null, array $context = array())
{
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format, $context)) {
return $normalizer->denormalize($data, $type, $format, $context);
}
}
}
public function supportsDenormalization($data, $type, $format = null)
{
return true;
}
}
class AbstractObjectNormalizerCollectionDummy extends AbstractObjectNormalizer
{
protected function extractAttributes($object, $format = null, array $context = array())
{
}
protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
{
}
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
{
$object->$attribute = $value;
}
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
{
return true;
}
public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, $format = null)
{
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
}
public function serialize($data, $format, array $context = array())
{
}
public function deserialize($data, $type, $format, array $context = array())
{
}
}
class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareInterface
{
/**
* @var SerializerInterface|DenormalizerInterface
*/
private $serializer;
/**
* {@inheritdoc}
*
* @throws NotNormalizableValueException
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
$serializer = $this->serializer;
$class = substr($class, 0, -2);
foreach ($data as $key => $value) {
$data[$key] = $serializer->denormalize($value, $class, $format, $context);
}
return $data;
}
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null, array $context = array())
{
return '[]' === substr($type, -2)
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
}
/**
* {@inheritdoc}
*/
public function setSerializer(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}
}

View file

@ -0,0 +1,122 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\ArrayDenormalizer;
use Symfony\Component\Serializer\SerializerInterface;
class ArrayDenormalizerTest extends TestCase
{
/**
* @var ArrayDenormalizer
*/
private $denormalizer;
/**
* @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $serializer;
protected function setUp()
{
$this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')->getMock();
$this->denormalizer = new ArrayDenormalizer();
$this->denormalizer->setSerializer($this->serializer);
}
public function testDenormalize()
{
$this->serializer->expects($this->at(0))
->method('denormalize')
->with(array('foo' => 'one', 'bar' => 'two'))
->will($this->returnValue(new ArrayDummy('one', 'two')));
$this->serializer->expects($this->at(1))
->method('denormalize')
->with(array('foo' => 'three', 'bar' => 'four'))
->will($this->returnValue(new ArrayDummy('three', 'four')));
$result = $this->denormalizer->denormalize(
array(
array('foo' => 'one', 'bar' => 'two'),
array('foo' => 'three', 'bar' => 'four'),
),
__NAMESPACE__.'\ArrayDummy[]'
);
$this->assertEquals(
array(
new ArrayDummy('one', 'two'),
new ArrayDummy('three', 'four'),
),
$result
);
}
public function testSupportsValidArray()
{
$this->serializer->expects($this->once())
->method('supportsDenormalization')
->with($this->anything(), __NAMESPACE__.'\ArrayDummy', $this->anything())
->will($this->returnValue(true));
$this->assertTrue(
$this->denormalizer->supportsDenormalization(
array(
array('foo' => 'one', 'bar' => 'two'),
array('foo' => 'three', 'bar' => 'four'),
),
__NAMESPACE__.'\ArrayDummy[]'
)
);
}
public function testSupportsInvalidArray()
{
$this->serializer->expects($this->any())
->method('supportsDenormalization')
->will($this->returnValue(false));
$this->assertFalse(
$this->denormalizer->supportsDenormalization(
array(
array('foo' => 'one', 'bar' => 'two'),
array('foo' => 'three', 'bar' => 'four'),
),
__NAMESPACE__.'\InvalidClass[]'
)
);
}
public function testSupportsNoArray()
{
$this->assertFalse(
$this->denormalizer->supportsDenormalization(
array('foo' => 'one', 'bar' => 'two'),
__NAMESPACE__.'\ArrayDummy'
)
);
}
}
class ArrayDummy
{
public $foo;
public $bar;
public function __construct($foo, $bar)
{
$this->foo = $foo;
$this->bar = $bar;
}
}

View file

@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\CustomNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy;
class CustomNormalizerTest extends TestCase
{
/**
* @var CustomNormalizer
*/
private $normalizer;
protected function setUp()
{
$this->normalizer = new CustomNormalizer();
$this->normalizer->setSerializer(new Serializer());
}
public function testInterface()
{
$this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\NormalizerInterface', $this->normalizer);
$this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\DenormalizerInterface', $this->normalizer);
$this->assertInstanceOf('Symfony\Component\Serializer\SerializerAwareInterface', $this->normalizer);
}
public function testSerialize()
{
$obj = new ScalarDummy();
$obj->foo = 'foo';
$obj->xmlFoo = 'xml';
$this->assertEquals('foo', $this->normalizer->normalize($obj, 'json'));
$this->assertEquals('xml', $this->normalizer->normalize($obj, 'xml'));
}
public function testDeserialize()
{
$obj = $this->normalizer->denormalize('foo', \get_class(new ScalarDummy()), 'xml');
$this->assertEquals('foo', $obj->xmlFoo);
$this->assertNull($obj->foo);
$obj = $this->normalizer->denormalize('foo', \get_class(new ScalarDummy()), 'json');
$this->assertEquals('foo', $obj->foo);
$this->assertNull($obj->xmlFoo);
}
public function testDenormalizeWithObjectToPopulateUsesProvidedObject()
{
$expected = new ScalarDummy();
$obj = $this->normalizer->denormalize('foo', ScalarDummy::class, 'json', array(
'object_to_populate' => $expected,
));
$this->assertSame($expected, $obj);
$this->assertEquals('foo', $obj->foo);
$this->assertNull($obj->xmlFoo);
}
public function testSupportsNormalization()
{
$this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
}
public function testSupportsDenormalization()
{
$this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy'));
$this->assertFalse($this->normalizer->supportsDenormalization(array(), 'stdClass'));
$this->assertTrue($this->normalizer->supportsDenormalization(array(), 'Symfony\Component\Serializer\Tests\Fixtures\DenormalizableDummy'));
}
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,137 @@
<?php
namespace Symfony\Component\Serializer\Tests\Normalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;
/**
* @author Jérôme Parmentier <jerome@prmntr.me>
*/
class DateIntervalNormalizerTest extends TestCase
{
/**
* @var DateIntervalNormalizer
*/
private $normalizer;
protected function setUp()
{
$this->normalizer = new DateIntervalNormalizer();
}
public function dataProviderISO()
{
$data = array(
array('P%YY%MM%DDT%HH%IM%SS', 'P00Y00M00DT00H00M00S', 'PT0S'),
array('P%yY%mM%dDT%hH%iM%sS', 'P0Y0M0DT0H0M0S', 'PT0S'),
array('P%yY%mM%dDT%hH%iM%sS', 'P10Y2M3DT16H5M6S', 'P10Y2M3DT16H5M6S'),
array('P%yY%mM%dDT%hH%iM', 'P10Y2M3DT16H5M', 'P10Y2M3DT16H5M'),
array('P%yY%mM%dDT%hH', 'P10Y2M3DT16H', 'P10Y2M3DT16H'),
array('P%yY%mM%dD', 'P10Y2M3D', 'P10Y2M3DT0H'),
);
return $data;
}
public function testSupportsNormalization()
{
$this->assertTrue($this->normalizer->supportsNormalization(new \DateInterval('P00Y00M00DT00H00M00S')));
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
}
public function testNormalize()
{
$this->assertEquals('P0Y0M0DT0H0M0S', $this->normalizer->normalize(new \DateInterval('PT0S')));
}
/**
* @dataProvider dataProviderISO
*/
public function testNormalizeUsingFormatPassedInContext($format, $output, $input)
{
$this->assertEquals($output, $this->normalizer->normalize(new \DateInterval($input), null, array(DateIntervalNormalizer::FORMAT_KEY => $format)));
}
/**
* @dataProvider dataProviderISO
*/
public function testNormalizeUsingFormatPassedInConstructor($format, $output, $input)
{
$this->assertEquals($output, (new DateIntervalNormalizer($format))->normalize(new \DateInterval($input)));
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
* @expectedExceptionMessage The object must be an instance of "\DateInterval".
*/
public function testNormalizeInvalidObjectThrowsException()
{
$this->normalizer->normalize(new \stdClass());
}
public function testSupportsDenormalization()
{
$this->assertTrue($this->normalizer->supportsDenormalization('P00Y00M00DT00H00M00S', \DateInterval::class));
$this->assertFalse($this->normalizer->supportsDenormalization('foo', 'Bar'));
}
public function testDenormalize()
{
$this->assertDateIntervalEquals(new \DateInterval('P00Y00M00DT00H00M00S'), $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class));
}
/**
* @dataProvider dataProviderISO
*/
public function testDenormalizeUsingFormatPassedInContext($format, $input, $output)
{
$this->assertDateIntervalEquals(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => $format)));
}
/**
* @dataProvider dataProviderISO
*/
public function testDenormalizeUsingFormatPassedInConstructor($format, $input, $output)
{
$this->assertDateIntervalEquals(new \DateInterval($output), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class));
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
*/
public function testDenormalizeExpectsString()
{
$this->normalizer->denormalize(1234, \DateInterval::class);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
* @expectedExceptionMessage Expected a valid ISO 8601 interval string.
*/
public function testDenormalizeNonISO8601IntervalStringThrowsException()
{
$this->normalizer->denormalize('10 years 2 months 3 days', \DateInterval::class, null);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDenormalizeInvalidDataThrowsException()
{
$this->normalizer->denormalize('invalid interval', \DateInterval::class);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDenormalizeFormatMismatchThrowsException()
{
$this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => 'P%yY%mM%dD'));
}
private function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual)
{
$this->assertEquals($expected->format('%RP%yY%mM%dDT%hH%iM%sS'), $actual->format('%RP%yY%mM%dDT%hH%iM%sS'));
}
}

View file

@ -0,0 +1,195 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\DateTimeNormalizer;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DateTimeNormalizerTest extends TestCase
{
/**
* @var DateTimeNormalizer
*/
private $normalizer;
protected function setUp()
{
$this->normalizer = new DateTimeNormalizer();
}
public function testSupportsNormalization()
{
$this->assertTrue($this->normalizer->supportsNormalization(new \DateTime()));
$this->assertTrue($this->normalizer->supportsNormalization(new \DateTimeImmutable()));
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
}
public function testNormalize()
{
$this->assertEquals('2016-01-01T00:00:00+00:00', $this->normalizer->normalize(new \DateTime('2016/01/01', new \DateTimeZone('UTC'))));
$this->assertEquals('2016-01-01T00:00:00+00:00', $this->normalizer->normalize(new \DateTimeImmutable('2016/01/01', new \DateTimeZone('UTC'))));
}
public function testNormalizeUsingFormatPassedInContext()
{
$this->assertEquals('2016', $this->normalizer->normalize(new \DateTime('2016/01/01'), null, array(DateTimeNormalizer::FORMAT_KEY => 'Y')));
}
public function testNormalizeUsingFormatPassedInConstructor()
{
$this->assertEquals('16', (new DateTimeNormalizer('y'))->normalize(new \DateTime('2016/01/01', new \DateTimeZone('UTC'))));
}
public function testNormalizeUsingTimeZonePassedInConstructor()
{
$normalizer = new DateTimeNormalizer(\DateTime::RFC3339, new \DateTimeZone('Japan'));
$this->assertSame('2016-12-01T00:00:00+09:00', $normalizer->normalize(new \DateTime('2016/12/01', new \DateTimeZone('Japan'))));
$this->assertSame('2016-12-01T09:00:00+09:00', $normalizer->normalize(new \DateTime('2016/12/01', new \DateTimeZone('UTC'))));
}
/**
* @dataProvider normalizeUsingTimeZonePassedInContextProvider
*/
public function testNormalizeUsingTimeZonePassedInContext($expected, $input, $timezone)
{
$this->assertSame($expected, $this->normalizer->normalize($input, null, array(
DateTimeNormalizer::TIMEZONE_KEY => $timezone,
)));
}
public function normalizeUsingTimeZonePassedInContextProvider()
{
yield array('2016-12-01T00:00:00+00:00', new \DateTime('2016/12/01', new \DateTimeZone('UTC')), null);
yield array('2016-12-01T00:00:00+09:00', new \DateTime('2016/12/01', new \DateTimeZone('Japan')), new \DateTimeZone('Japan'));
yield array('2016-12-01T09:00:00+09:00', new \DateTime('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan'));
yield array('2016-12-01T09:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan'));
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
* @expectedExceptionMessage The object must implement the "\DateTimeInterface".
*/
public function testNormalizeInvalidObjectThrowsException()
{
$this->normalizer->normalize(new \stdClass());
}
public function testSupportsDenormalization()
{
$this->assertTrue($this->normalizer->supportsDenormalization('2016-01-01T00:00:00+00:00', \DateTimeInterface::class));
$this->assertTrue($this->normalizer->supportsDenormalization('2016-01-01T00:00:00+00:00', \DateTime::class));
$this->assertTrue($this->normalizer->supportsDenormalization('2016-01-01T00:00:00+00:00', \DateTimeImmutable::class));
$this->assertFalse($this->normalizer->supportsDenormalization('foo', 'Bar'));
}
public function testDenormalize()
{
$this->assertEquals(new \DateTimeImmutable('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTimeInterface::class));
$this->assertEquals(new \DateTimeImmutable('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTimeImmutable::class));
$this->assertEquals(new \DateTime('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTime::class));
}
public function testDenormalizeUsingTimezonePassedInConstructor()
{
$timezone = new \DateTimeZone('Japan');
$expected = new \DateTime('2016/12/01 17:35:00', $timezone);
$normalizer = new DateTimeNormalizer(null, $timezone);
$this->assertEquals($expected, $normalizer->denormalize('2016.12.01 17:35:00', \DateTime::class, null, array(
DateTimeNormalizer::FORMAT_KEY => 'Y.m.d H:i:s',
)));
}
public function testDenormalizeUsingFormatPassedInContext()
{
$this->assertEquals(new \DateTimeImmutable('2016/01/01'), $this->normalizer->denormalize('2016.01.01', \DateTimeInterface::class, null, array(DateTimeNormalizer::FORMAT_KEY => 'Y.m.d|')));
$this->assertEquals(new \DateTimeImmutable('2016/01/01'), $this->normalizer->denormalize('2016.01.01', \DateTimeImmutable::class, null, array(DateTimeNormalizer::FORMAT_KEY => 'Y.m.d|')));
$this->assertEquals(new \DateTime('2016/01/01'), $this->normalizer->denormalize('2016.01.01', \DateTime::class, null, array(DateTimeNormalizer::FORMAT_KEY => 'Y.m.d|')));
}
/**
* @dataProvider denormalizeUsingTimezonePassedInContextProvider
*/
public function testDenormalizeUsingTimezonePassedInContext($input, $expected, $timezone, $format = null)
{
$actual = $this->normalizer->denormalize($input, \DateTimeInterface::class, null, array(
DateTimeNormalizer::TIMEZONE_KEY => $timezone,
DateTimeNormalizer::FORMAT_KEY => $format,
));
$this->assertEquals($expected, $actual);
}
public function denormalizeUsingTimezonePassedInContextProvider()
{
yield 'with timezone' => array(
'2016/12/01 17:35:00',
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
new \DateTimeZone('Japan'),
);
yield 'with timezone as string' => array(
'2016/12/01 17:35:00',
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
'Japan',
);
yield 'with format without timezone information' => array(
'2016.12.01 17:35:00',
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
new \DateTimeZone('Japan'),
'Y.m.d H:i:s',
);
yield 'ignored with format with timezone information' => array(
'2016-12-01T17:35:00Z',
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('UTC')),
'Europe/Paris',
\DateTime::RFC3339,
);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDenormalizeInvalidDataThrowsException()
{
$this->normalizer->denormalize('invalid date', \DateTimeInterface::class);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
* @expectedExceptionMessage The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid DateTime string.
*/
public function testDenormalizeNullThrowsException()
{
$this->normalizer->denormalize(null, \DateTimeInterface::class);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
* @expectedExceptionMessage The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid DateTime string.
*/
public function testDenormalizeEmptyStringThrowsException()
{
$this->normalizer->denormalize('', \DateTimeInterface::class);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDenormalizeFormatMismatchThrowsException()
{
$this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTimeInterface::class, null, array(DateTimeNormalizer::FORMAT_KEY => 'Y-m-d|'));
}
}

View file

@ -0,0 +1,841 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
class GetSetMethodNormalizerTest extends TestCase
{
/**
* @var GetSetMethodNormalizer
*/
private $normalizer;
/**
* @var SerializerInterface
*/
private $serializer;
protected function setUp()
{
$this->serializer = $this->getMockBuilder(__NAMESPACE__.'\SerializerNormalizer')->getMock();
$this->normalizer = new GetSetMethodNormalizer();
$this->normalizer->setSerializer($this->serializer);
}
public function testInterface()
{
$this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\NormalizerInterface', $this->normalizer);
$this->assertInstanceOf('Symfony\Component\Serializer\Normalizer\DenormalizerInterface', $this->normalizer);
}
public function testNormalize()
{
$obj = new GetSetDummy();
$object = new \stdClass();
$obj->setFoo('foo');
$obj->setBar('bar');
$obj->setBaz(true);
$obj->setCamelCase('camelcase');
$obj->setObject($object);
$this->serializer
->expects($this->once())
->method('normalize')
->with($object, 'any')
->will($this->returnValue('string_object'))
;
$this->assertEquals(
array(
'foo' => 'foo',
'bar' => 'bar',
'baz' => true,
'fooBar' => 'foobar',
'camelCase' => 'camelcase',
'object' => 'string_object',
),
$this->normalizer->normalize($obj, 'any')
);
}
public function testDenormalize()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
__NAMESPACE__.'\GetSetDummy',
'any'
);
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
$this->assertTrue($obj->isBaz());
}
public function testDenormalizeWithObject()
{
$data = new \stdClass();
$data->foo = 'foo';
$data->bar = 'bar';
$data->fooBar = 'foobar';
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetSetDummy', 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
public function testDenormalizeNull()
{
$this->assertEquals(new GetSetDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\GetSetDummy'));
}
public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
__NAMESPACE__.'\GetConstructorDummy', 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
$this->assertTrue($obj->isBaz());
}
public function testConstructorDenormalizeWithNullArgument()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => null, 'baz' => true),
__NAMESPACE__.'\GetConstructorDummy', 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertNull($obj->getBar());
$this->assertTrue($obj->isBaz());
}
public function testConstructorDenormalizeWithMissingOptionalArgument()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'test', 'baz' => array(1, 2, 3)),
__NAMESPACE__.'\GetConstructorOptionalArgsDummy', 'any');
$this->assertEquals('test', $obj->getFoo());
$this->assertEquals(array(), $obj->getBar());
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
}
public function testConstructorDenormalizeWithOptionalDefaultArgument()
{
$obj = $this->normalizer->denormalize(
array('bar' => 'test'),
__NAMESPACE__.'\GetConstructorArgsWithDefaultValueDummy', 'any');
$this->assertEquals(array(), $obj->getFoo());
$this->assertEquals('test', $obj->getBar());
}
/**
* @requires PHP 5.6
*/
public function testConstructorDenormalizeWithVariadicArgument()
{
$obj = $this->normalizer->denormalize(
array('foo' => array(1, 2, 3)),
'Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorArgsDummy', 'any');
$this->assertEquals(array(1, 2, 3), $obj->getFoo());
}
/**
* @requires PHP 5.6
*/
public function testConstructorDenormalizeWithMissingVariadicArgument()
{
$obj = $this->normalizer->denormalize(
array(),
'Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorArgsDummy', 'any');
$this->assertEquals(array(), $obj->getFoo());
}
public function testConstructorWithObjectDenormalize()
{
$data = new \stdClass();
$data->foo = 'foo';
$data->bar = 'bar';
$data->baz = true;
$data->fooBar = 'foobar';
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any');
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
public function testConstructorWArgWithPrivateMutator()
{
$obj = $this->normalizer->denormalize(array('foo' => 'bar'), __NAMESPACE__.'\ObjectConstructorArgsWithPrivateMutatorDummy', 'any');
$this->assertEquals('bar', $obj->getFoo());
}
public function testGroupsNormalize()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFoo('foo');
$obj->setBar('bar');
$obj->setFooBar('fooBar');
$obj->setSymfony('symfony');
$obj->setKevin('kevin');
$obj->setCoopTilleuls('coopTilleuls');
$this->assertEquals(array(
'bar' => 'bar',
), $this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('c'))));
$this->assertEquals(array(
'symfony' => 'symfony',
'foo' => 'foo',
'fooBar' => 'fooBar',
'bar' => 'bar',
'kevin' => 'kevin',
'coopTilleuls' => 'coopTilleuls',
), $this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('a', 'c'))));
}
public function testGroupsDenormalize()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFoo('foo');
$toNormalize = array('foo' => 'foo', 'bar' => 'bar');
$normalized = $this->normalizer->denormalize(
$toNormalize,
'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
null,
array(GetSetMethodNormalizer::GROUPS => array('a'))
);
$this->assertEquals($obj, $normalized);
$obj->setBar('bar');
$normalized = $this->normalizer->denormalize(
$toNormalize,
'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
null,
array(GetSetMethodNormalizer::GROUPS => array('a', 'b'))
);
$this->assertEquals($obj, $normalized);
}
public function testGroupsNormalizeWithNameConverter()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFooBar('@dunglas');
$obj->setSymfony('@coopTilleuls');
$obj->setCoopTilleuls('les-tilleuls.coop');
$this->assertEquals(
array(
'bar' => null,
'foo_bar' => '@dunglas',
'symfony' => '@coopTilleuls',
),
$this->normalizer->normalize($obj, null, array(GetSetMethodNormalizer::GROUPS => array('name_converter')))
);
}
public function testGroupsDenormalizeWithNameConverter()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFooBar('@dunglas');
$obj->setSymfony('@coopTilleuls');
$this->assertEquals(
$obj,
$this->normalizer->denormalize(array(
'bar' => null,
'foo_bar' => '@dunglas',
'symfony' => '@coopTilleuls',
'coop_tilleuls' => 'les-tilleuls.coop',
), 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy', null, array(GetSetMethodNormalizer::GROUPS => array('name_converter')))
);
}
/**
* @dataProvider provideCallbacks
*/
public function testCallbacks($callbacks, $value, $result, $message)
{
$this->normalizer->setCallbacks($callbacks);
$obj = new GetConstructorDummy('', $value, true);
$this->assertEquals(
$result,
$this->normalizer->normalize($obj, 'any'),
$message
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testUncallableCallbacks()
{
$this->normalizer->setCallbacks(array('bar' => null));
$obj = new GetConstructorDummy('baz', 'quux', true);
$this->normalizer->normalize($obj, 'any');
}
public function testIgnoredAttributes()
{
$this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'baz', 'camelCase', 'object'));
$obj = new GetSetDummy();
$obj->setFoo('foo');
$obj->setBar('bar');
$obj->setBaz(true);
$this->assertEquals(
array('fooBar' => 'foobar'),
$this->normalizer->normalize($obj, 'any')
);
}
public function provideCallbacks()
{
return array(
array(
array(
'bar' => function ($bar) {
return 'baz';
},
),
'baz',
array('foo' => '', 'bar' => 'baz', 'baz' => true),
'Change a string',
),
array(
array(
'bar' => function ($bar) {
},
),
'baz',
array('foo' => '', 'bar' => null, 'baz' => true),
'Null an item',
),
array(
array(
'bar' => function ($bar) {
return $bar->format('d-m-Y H:i:s');
},
),
new \DateTime('2011-09-10 06:30:00'),
array('foo' => '', 'bar' => '10-09-2011 06:30:00', 'baz' => true),
'Format a date',
),
array(
array(
'bar' => function ($bars) {
$foos = '';
foreach ($bars as $bar) {
$foos .= $bar->getFoo();
}
return $foos;
},
),
array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)),
array('foo' => '', 'bar' => 'bazquux', 'baz' => true),
'Collect a property',
),
array(
array(
'bar' => function ($bars) {
return \count($bars);
},
),
array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)),
array('foo' => '', 'bar' => 2, 'baz' => true),
'Count a property',
),
);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
* @expectedExceptionMessage Cannot normalize attribute "object" because the injected serializer is not a normalizer
*/
public function testUnableToNormalizeObjectAttribute()
{
$serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')->getMock();
$this->normalizer->setSerializer($serializer);
$obj = new GetSetDummy();
$object = new \stdClass();
$obj->setObject($object);
$this->normalizer->normalize($obj, 'any');
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException
*/
public function testUnableToNormalizeCircularReference()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$this->normalizer->setCircularReferenceLimit(2);
$obj = new CircularReferenceDummy();
$this->normalizer->normalize($obj);
}
public function testSiblingReference()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$siblingHolder = new SiblingHolder();
$expected = array(
'sibling0' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
'sibling1' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
'sibling2' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
);
$this->assertEquals($expected, $this->normalizer->normalize($siblingHolder));
}
public function testCircularReferenceHandler()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$this->normalizer->setCircularReferenceHandler(function ($obj) {
return \get_class($obj);
});
$obj = new CircularReferenceDummy();
$expected = array('me' => 'Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy');
$this->assertEquals($expected, $this->normalizer->normalize($obj));
}
public function testObjectToPopulate()
{
$dummy = new GetSetDummy();
$dummy->setFoo('foo');
$obj = $this->normalizer->denormalize(
array('bar' => 'bar'),
__NAMESPACE__.'\GetSetDummy',
null,
array(GetSetMethodNormalizer::OBJECT_TO_POPULATE => $dummy)
);
$this->assertEquals($dummy, $obj);
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
public function testDenormalizeNonExistingAttribute()
{
$this->assertEquals(
new GetSetDummy(),
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\GetSetDummy')
);
}
public function testDenormalizeShouldNotSetStaticAttribute()
{
$obj = $this->normalizer->denormalize(array('staticObject' => true), __NAMESPACE__.'\GetSetDummy');
$this->assertEquals(new GetSetDummy(), $obj);
$this->assertNull(GetSetDummy::getStaticObject());
}
public function testNoTraversableSupport()
{
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
}
public function testNoStaticGetSetSupport()
{
$this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
}
public function testPrivateSetter()
{
$obj = $this->normalizer->denormalize(array('foo' => 'foobar'), __NAMESPACE__.'\ObjectWithPrivateSetterDummy');
$this->assertEquals('bar', $obj->getFoo());
}
public function testHasGetterDenormalize()
{
$obj = $this->normalizer->denormalize(array('foo' => true), ObjectWithHasGetterDummy::class);
$this->assertTrue($obj->hasFoo());
}
public function testHasGetterNormalize()
{
$obj = new ObjectWithHasGetterDummy();
$obj->setFoo(true);
$this->assertEquals(
array('foo' => true),
$this->normalizer->normalize($obj, 'any')
);
}
public function testMaxDepth()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory);
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$level1 = new MaxDepthDummy();
$level1->bar = 'level1';
$level2 = new MaxDepthDummy();
$level2->bar = 'level2';
$level1->child = $level2;
$level3 = new MaxDepthDummy();
$level3->bar = 'level3';
$level2->child = $level3;
$level4 = new MaxDepthDummy();
$level4->bar = 'level4';
$level3->child = $level4;
$result = $serializer->normalize($level1, null, array(GetSetMethodNormalizer::ENABLE_MAX_DEPTH => true));
$expected = array(
'bar' => 'level1',
'child' => array(
'bar' => 'level2',
'child' => array(
'bar' => 'level3',
'child' => array(
'child' => null,
),
),
),
);
$this->assertEquals($expected, $result);
}
}
class GetSetDummy
{
protected $foo;
private $bar;
private $baz;
protected $camelCase;
protected $object;
private static $staticObject;
public function getFoo()
{
return $this->foo;
}
public function setFoo($foo)
{
$this->foo = $foo;
}
public function getBar()
{
return $this->bar;
}
public function setBar($bar)
{
$this->bar = $bar;
}
public function isBaz()
{
return $this->baz;
}
public function setBaz($baz)
{
$this->baz = $baz;
}
public function getFooBar()
{
return $this->foo.$this->bar;
}
public function getCamelCase()
{
return $this->camelCase;
}
public function setCamelCase($camelCase)
{
$this->camelCase = $camelCase;
}
public function otherMethod()
{
throw new \RuntimeException('Dummy::otherMethod() should not be called');
}
public function setObject($object)
{
$this->object = $object;
}
public function getObject()
{
return $this->object;
}
public static function getStaticObject()
{
return self::$staticObject;
}
public static function setStaticObject($object)
{
self::$staticObject = $object;
}
protected function getPrivate()
{
throw new \RuntimeException('Dummy::getPrivate() should not be called');
}
}
class GetConstructorDummy
{
protected $foo;
private $bar;
private $baz;
public function __construct($foo, $bar, $baz)
{
$this->foo = $foo;
$this->bar = $bar;
$this->baz = $baz;
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->bar;
}
public function isBaz()
{
return $this->baz;
}
public function otherMethod()
{
throw new \RuntimeException('Dummy::otherMethod() should not be called');
}
}
abstract class SerializerNormalizer implements SerializerInterface, NormalizerInterface
{
}
class GetConstructorOptionalArgsDummy
{
protected $foo;
private $bar;
private $baz;
public function __construct($foo, $bar = array(), $baz = array())
{
$this->foo = $foo;
$this->bar = $bar;
$this->baz = $baz;
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->bar;
}
public function getBaz()
{
return $this->baz;
}
public function otherMethod()
{
throw new \RuntimeException('Dummy::otherMethod() should not be called');
}
}
class GetConstructorArgsWithDefaultValueDummy
{
protected $foo;
protected $bar;
public function __construct($foo = array(), $bar)
{
$this->foo = $foo;
$this->bar = $bar;
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->bar;
}
public function otherMethod()
{
throw new \RuntimeException('Dummy::otherMethod() should not be called');
}
}
class GetCamelizedDummy
{
private $kevinDunglas;
private $fooBar;
private $bar_foo;
public function __construct($kevinDunglas = null)
{
$this->kevinDunglas = $kevinDunglas;
}
public function getKevinDunglas()
{
return $this->kevinDunglas;
}
public function setFooBar($fooBar)
{
$this->fooBar = $fooBar;
}
public function getFooBar()
{
return $this->fooBar;
}
public function setBar_foo($bar_foo)
{
$this->bar_foo = $bar_foo;
}
public function getBar_foo()
{
return $this->bar_foo;
}
}
class ObjectConstructorArgsWithPrivateMutatorDummy
{
private $foo;
public function __construct($foo)
{
$this->setFoo($foo);
}
public function getFoo()
{
return $this->foo;
}
private function setFoo($foo)
{
$this->foo = $foo;
}
}
class ObjectWithPrivateSetterDummy
{
private $foo = 'bar';
public function getFoo()
{
return $this->foo;
}
private function setFoo($foo)
{
}
}
class ObjectWithJustStaticSetterDummy
{
private static $foo = 'bar';
public static function getFoo()
{
return self::$foo;
}
public static function setFoo($foo)
{
self::$foo = $foo;
}
}
class ObjectWithHasGetterDummy
{
private $foo;
public function setFoo($foo)
{
$this->foo = $foo;
}
public function hasFoo()
{
return $this->foo;
}
}

View file

@ -0,0 +1,95 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <mcfedr@gmail.com>
*/
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
{
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,47 @@
<?php
namespace Symfony\Component\Serializer\Tests\Normalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;
class ObjectToPopulateTraitTest extends TestCase
{
use ObjectToPopulateTrait;
public function testExtractObjectToPopulateReturnsNullWhenKeyIsMissing()
{
$object = $this->extractObjectToPopulate(ProxyDummy::class, array());
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsNullWhenNonObjectIsProvided()
{
$object = $this->extractObjectToPopulate(ProxyDummy::class, array(
'object_to_populate' => 'not an object',
));
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsNullWhenTheClassIsNotAnInstanceOfTheProvidedClass()
{
$object = $this->extractObjectToPopulate(ProxyDummy::class, array(
'object_to_populate' => new \stdClass(),
));
$this->assertNull($object);
}
public function testExtractObjectToPopulateReturnsObjectWhenEverythingChecksOut()
{
$expected = new ProxyDummy();
$object = $this->extractObjectToPopulate(ProxyDummy::class, array(
'object_to_populate' => $expected,
));
$this->assertSame($expected, $object);
}
}

View file

@ -0,0 +1,524 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
use Symfony\Component\Serializer\Tests\Fixtures\GroupDummyChild;
use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
use Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy;
use Symfony\Component\Serializer\Tests\Fixtures\PropertySiblingHolder;
class PropertyNormalizerTest extends TestCase
{
/**
* @var PropertyNormalizer
*/
private $normalizer;
/**
* @var SerializerInterface
*/
private $serializer;
protected function setUp()
{
$this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')->getMock();
$this->normalizer = new PropertyNormalizer();
$this->normalizer->setSerializer($this->serializer);
}
public function testNormalize()
{
$obj = new PropertyDummy();
$obj->foo = 'foo';
$obj->setBar('bar');
$obj->setCamelCase('camelcase');
$this->assertEquals(
array('foo' => 'foo', 'bar' => 'bar', 'camelCase' => 'camelcase'),
$this->normalizer->normalize($obj, 'any')
);
}
public function testDenormalize()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar'),
__NAMESPACE__.'\PropertyDummy',
'any'
);
$this->assertEquals('foo', $obj->foo);
$this->assertEquals('bar', $obj->getBar());
}
public function testNormalizeWithParentClass()
{
$group = new GroupDummyChild();
$group->setBaz('baz');
$group->setFoo('foo');
$group->setBar('bar');
$group->setKevin('Kevin');
$group->setCoopTilleuls('coop');
$this->assertEquals(
array('foo' => 'foo', 'bar' => 'bar', 'kevin' => 'Kevin', 'coopTilleuls' => 'coop', 'fooBar' => null, 'symfony' => null, 'baz' => 'baz'),
$this->normalizer->normalize($group, 'any')
);
}
public function testDenormalizeWithParentClass()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar', 'kevin' => 'Kevin', 'baz' => 'baz'),
GroupDummyChild::class,
'any'
);
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
$this->assertEquals('Kevin', $obj->getKevin());
$this->assertEquals('baz', $obj->getBaz());
$this->assertNull($obj->getSymfony());
}
public function testConstructorDenormalize()
{
$obj = $this->normalizer->denormalize(
array('foo' => 'foo', 'bar' => 'bar'),
__NAMESPACE__.'\PropertyConstructorDummy',
'any'
);
$this->assertEquals('foo', $obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
public function testConstructorDenormalizeWithNullArgument()
{
$obj = $this->normalizer->denormalize(
array('foo' => null, 'bar' => 'bar'),
__NAMESPACE__.'\PropertyConstructorDummy', '
any'
);
$this->assertNull($obj->getFoo());
$this->assertEquals('bar', $obj->getBar());
}
/**
* @dataProvider provideCallbacks
*/
public function testCallbacks($callbacks, $value, $result, $message)
{
$this->normalizer->setCallbacks($callbacks);
$obj = new PropertyConstructorDummy('', $value);
$this->assertEquals(
$result,
$this->normalizer->normalize($obj, 'any'),
$message
);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testUncallableCallbacks()
{
$this->normalizer->setCallbacks(array('bar' => null));
$obj = new PropertyConstructorDummy('baz', 'quux');
$this->normalizer->normalize($obj, 'any');
}
public function testIgnoredAttributes()
{
$this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'camelCase'));
$obj = new PropertyDummy();
$obj->foo = 'foo';
$obj->setBar('bar');
$this->assertEquals(
array(),
$this->normalizer->normalize($obj, 'any')
);
}
public function testGroupsNormalize()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new PropertyNormalizer($classMetadataFactory);
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFoo('foo');
$obj->setBar('bar');
$obj->setFooBar('fooBar');
$obj->setSymfony('symfony');
$obj->setKevin('kevin');
$obj->setCoopTilleuls('coopTilleuls');
$this->assertEquals(array(
'bar' => 'bar',
), $this->normalizer->normalize($obj, null, array(PropertyNormalizer::GROUPS => array('c'))));
// The PropertyNormalizer is also able to hydrate properties from parent classes
$this->assertEquals(array(
'symfony' => 'symfony',
'foo' => 'foo',
'fooBar' => 'fooBar',
'bar' => 'bar',
'kevin' => 'kevin',
'coopTilleuls' => 'coopTilleuls',
), $this->normalizer->normalize($obj, null, array(PropertyNormalizer::GROUPS => array('a', 'c'))));
}
public function testGroupsDenormalize()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new PropertyNormalizer($classMetadataFactory);
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFoo('foo');
$toNormalize = array('foo' => 'foo', 'bar' => 'bar');
$normalized = $this->normalizer->denormalize(
$toNormalize,
'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
null,
array(PropertyNormalizer::GROUPS => array('a'))
);
$this->assertEquals($obj, $normalized);
$obj->setBar('bar');
$normalized = $this->normalizer->denormalize(
$toNormalize,
'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
null,
array(PropertyNormalizer::GROUPS => array('a', 'b'))
);
$this->assertEquals($obj, $normalized);
}
public function testGroupsNormalizeWithNameConverter()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new PropertyNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFooBar('@dunglas');
$obj->setSymfony('@coopTilleuls');
$obj->setCoopTilleuls('les-tilleuls.coop');
$this->assertEquals(
array(
'bar' => null,
'foo_bar' => '@dunglas',
'symfony' => '@coopTilleuls',
),
$this->normalizer->normalize($obj, null, array(PropertyNormalizer::GROUPS => array('name_converter')))
);
}
public function testGroupsDenormalizeWithNameConverter()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new PropertyNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
$this->normalizer->setSerializer($this->serializer);
$obj = new GroupDummy();
$obj->setFooBar('@dunglas');
$obj->setSymfony('@coopTilleuls');
$this->assertEquals(
$obj,
$this->normalizer->denormalize(array(
'bar' => null,
'foo_bar' => '@dunglas',
'symfony' => '@coopTilleuls',
'coop_tilleuls' => 'les-tilleuls.coop',
), 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy', null, array(PropertyNormalizer::GROUPS => array('name_converter')))
);
}
public function provideCallbacks()
{
return array(
array(
array(
'bar' => function ($bar) {
return 'baz';
},
),
'baz',
array('foo' => '', 'bar' => 'baz'),
'Change a string',
),
array(
array(
'bar' => function ($bar) {
return;
},
),
'baz',
array('foo' => '', 'bar' => null),
'Null an item',
),
array(
array(
'bar' => function ($bar) {
return $bar->format('d-m-Y H:i:s');
},
),
new \DateTime('2011-09-10 06:30:00'),
array('foo' => '', 'bar' => '10-09-2011 06:30:00'),
'Format a date',
),
array(
array(
'bar' => function ($bars) {
$foos = '';
foreach ($bars as $bar) {
$foos .= $bar->getFoo();
}
return $foos;
},
),
array(new PropertyConstructorDummy('baz', ''), new PropertyConstructorDummy('quux', '')),
array('foo' => '', 'bar' => 'bazquux'),
'Collect a property',
),
array(
array(
'bar' => function ($bars) {
return \count($bars);
},
),
array(new PropertyConstructorDummy('baz', ''), new PropertyConstructorDummy('quux', '')),
array('foo' => '', 'bar' => 2),
'Count a property',
),
);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException
*/
public function testUnableToNormalizeCircularReference()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$this->normalizer->setCircularReferenceLimit(2);
$obj = new PropertyCircularReferenceDummy();
$this->normalizer->normalize($obj);
}
public function testSiblingReference()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$siblingHolder = new PropertySiblingHolder();
$expected = array(
'sibling0' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
'sibling1' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
'sibling2' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
);
$this->assertEquals($expected, $this->normalizer->normalize($siblingHolder));
}
public function testCircularReferenceHandler()
{
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$this->normalizer->setCircularReferenceHandler(function ($obj) {
return \get_class($obj);
});
$obj = new PropertyCircularReferenceDummy();
$expected = array('me' => 'Symfony\Component\Serializer\Tests\Fixtures\PropertyCircularReferenceDummy');
$this->assertEquals($expected, $this->normalizer->normalize($obj));
}
public function testDenormalizeNonExistingAttribute()
{
$this->assertEquals(
new PropertyDummy(),
$this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\PropertyDummy')
);
}
public function testDenormalizeShouldIgnoreStaticProperty()
{
$obj = $this->normalizer->denormalize(array('outOfScope' => true), __NAMESPACE__.'\PropertyDummy');
$this->assertEquals(new PropertyDummy(), $obj);
$this->assertEquals('out_of_scope', PropertyDummy::$outOfScope);
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
* @expectedExceptionMessage Cannot normalize attribute "bar" because the injected serializer is not a normalizer
*/
public function testUnableToNormalizeObjectAttribute()
{
$serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')->getMock();
$this->normalizer->setSerializer($serializer);
$obj = new PropertyDummy();
$object = new \stdClass();
$obj->setBar($object);
$this->normalizer->normalize($obj, 'any');
}
public function testNoTraversableSupport()
{
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
}
public function testNoStaticPropertySupport()
{
$this->assertFalse($this->normalizer->supportsNormalization(new StaticPropertyDummy()));
}
public function testMaxDepth()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new PropertyNormalizer($classMetadataFactory);
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$level1 = new MaxDepthDummy();
$level1->foo = 'level1';
$level2 = new MaxDepthDummy();
$level2->foo = 'level2';
$level1->child = $level2;
$level3 = new MaxDepthDummy();
$level3->foo = 'level3';
$level2->child = $level3;
$result = $serializer->normalize($level1, null, array(PropertyNormalizer::ENABLE_MAX_DEPTH => true));
$expected = array(
'foo' => 'level1',
'child' => array(
'foo' => 'level2',
'child' => array(
'child' => null,
'bar' => null,
),
'bar' => null,
),
'bar' => null,
);
$this->assertEquals($expected, $result);
}
public function testInheritedPropertiesSupport()
{
$this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
}
}
class PropertyDummy
{
public static $outOfScope = 'out_of_scope';
public $foo;
private $bar;
protected $camelCase;
public function getBar()
{
return $this->bar;
}
public function setBar($bar)
{
$this->bar = $bar;
}
public function getCamelCase()
{
return $this->camelCase;
}
public function setCamelCase($camelCase)
{
$this->camelCase = $camelCase;
}
}
class PropertyConstructorDummy
{
protected $foo;
private $bar;
public function __construct($foo, $bar)
{
$this->foo = $foo;
$this->bar = $bar;
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->bar;
}
}
class PropertyCamelizedDummy
{
private $kevinDunglas;
public $fooBar;
public $bar_foo;
public function __construct($kevinDunglas = null)
{
$this->kevinDunglas = $kevinDunglas;
}
}
class StaticPropertyDummy
{
private static $property = 'value';
}
class PropertyParentDummy
{
private $foo = 'bar';
}
class PropertyChildDummy extends PropertyParentDummy
{
}

View file

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
/**
* Provides a test Normalizer which only implements the DenormalizerInterface.
*
* @author Lin Clark <lin@lin-clark.com>
*/
class TestDenormalizer implements DenormalizerInterface
{
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
}
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null)
{
return true;
}
}

View file

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Provides a test Normalizer which only implements the NormalizerInterface.
*
* @author Lin Clark <lin@lin-clark.com>
*/
class TestNormalizer implements NormalizerInterface
{
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = array())
{
}
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
{
return true;
}
}