From 8f96bbb492b2a5dcbee44c6db6202950f52e7577 Mon Sep 17 00:00:00 2001 From: George Mponos Date: Mon, 14 Jan 2019 23:07:15 +0200 Subject: [PATCH 1/2] [Serializer] Docblock about throwing exceptions on serializer --- Normalizer/DenormalizerInterface.php | 4 +++- Normalizer/NormalizerInterface.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Normalizer/DenormalizerInterface.php b/Normalizer/DenormalizerInterface.php index c3a2bb535632..7a12d20f1132 100644 --- a/Normalizer/DenormalizerInterface.php +++ b/Normalizer/DenormalizerInterface.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Serializer\Normalizer; use Symfony\Component\Serializer\Exception\BadMethodCallException; +use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Exception\ExtraAttributesException; use Symfony\Component\Serializer\Exception\InvalidArgumentException; use Symfony\Component\Serializer\Exception\LogicException; @@ -41,8 +42,9 @@ interface DenormalizerInterface * @throws ExtraAttributesException Occurs when the item doesn't have attribute to receive given data * @throws LogicException Occurs when the normalizer is not supposed to denormalize * @throws RuntimeException Occurs if the class cannot be instantiated + * @throws ExceptionInterface Occurs for all the other cases of errors */ - public function denormalize($data, $class, $format = null, array $context = array()); + public function denormalize($data, $class, $format = null, array $context = []); /** * Checks whether the given class is supported for denormalization by this normalizer. diff --git a/Normalizer/NormalizerInterface.php b/Normalizer/NormalizerInterface.php index 5cccdb336009..02a211858492 100644 --- a/Normalizer/NormalizerInterface.php +++ b/Normalizer/NormalizerInterface.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Serializer\Normalizer; use Symfony\Component\Serializer\Exception\CircularReferenceException; +use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Exception\InvalidArgumentException; use Symfony\Component\Serializer\Exception\LogicException; @@ -35,8 +36,9 @@ interface NormalizerInterface * @throws CircularReferenceException Occurs when the normalizer detects a circular reference when no circular * reference handler can fix it * @throws LogicException Occurs when the normalizer is not called in an expected context + * @throws ExceptionInterface Occurs for all the other cases of errors */ - public function normalize($object, $format = null, array $context = array()); + public function normalize($object, $format = null, array $context = []); /** * Checks whether the given class is supported for normalization by this normalizer. From d14aa48a1818bc77b3bcd91616e94930d7603ac5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 18 Jan 2019 18:22:25 +0100 Subject: [PATCH 2/2] [Form] ensure compatibility with older PHPUnit mocks --- Tests/Mapping/ClassMetadataTest.php | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/Tests/Mapping/ClassMetadataTest.php b/Tests/Mapping/ClassMetadataTest.php index f62967935dc5..636d8a8ab891 100644 --- a/Tests/Mapping/ClassMetadataTest.php +++ b/Tests/Mapping/ClassMetadataTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Serializer\Tests\Mapping; use PHPUnit\Framework\TestCase; +use Symfony\Component\Serializer\Mapping\AttributeMetadata; use Symfony\Component\Serializer\Mapping\ClassMetadata; /** @@ -29,11 +30,8 @@ public function testAttributeMetadata() { $classMetadata = new ClassMetadata('c'); - $a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $a1->method('getName')->willReturn('a1'); - - $a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $a2->method('getName')->willReturn('a2'); + $a1 = new AttributeMetadata('a1'); + $a2 = new AttributeMetadata('a2'); $classMetadata->addAttributeMetadata($a1); $classMetadata->addAttributeMetadata($a2); @@ -46,33 +44,28 @@ public function testMerge() $classMetadata1 = new ClassMetadata('c1'); $classMetadata2 = new ClassMetadata('c2'); - $ac1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $ac1->method('getName')->willReturn('a1'); - $ac1->method('getGroups')->willReturn(['a', 'b']); - - $ac2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $ac2->method('getName')->willReturn('a1'); - $ac2->method('getGroups')->willReturn(['b', 'c']); + $ac1 = new AttributeMetadata('a1'); + $ac1->addGroup('a'); + $ac1->addGroup('b'); + $ac2 = new AttributeMetadata('a1'); + $ac2->addGroup('b'); + $ac2->addGroup('c'); $classMetadata1->addAttributeMetadata($ac1); $classMetadata2->addAttributeMetadata($ac2); $classMetadata1->merge($classMetadata2); - $ac1->method('getGroups')->willReturn('a', 'b', 'c'); - - $this->assertEquals(['a1' => $ac1], $classMetadata2->getAttributesMetadata()); + $this->assertSame(['a', 'b', 'c'], $ac1->getGroups()); + $this->assertEquals(['a1' => $ac1], $classMetadata1->getAttributesMetadata()); } public function testSerialize() { $classMetadata = new ClassMetadata('a'); - $a1 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $a1->method('getName')->willReturn('b1'); - - $a2 = $this->getMockBuilder('Symfony\Component\Serializer\Mapping\AttributeMetadataInterface')->getMock(); - $a2->method('getName')->willReturn('b2'); + $a1 = new AttributeMetadata('b1'); + $a2 = new AttributeMetadata('b2'); $classMetadata->addAttributeMetadata($a1); $classMetadata->addAttributeMetadata($a2);