From 999f769ba545e3eb9fb91df5e2fce7320834b9b2 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 15 Dec 2016 20:58:01 +0100 Subject: [PATCH] [Serializer] Fix MaxDepth annotation exceptions --- .../Serializer/Annotation/MaxDepth.php | 4 ++-- .../Tests/Annotation/MaxDepthTest.php | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Serializer/Annotation/MaxDepth.php b/src/Symfony/Component/Serializer/Annotation/MaxDepth.php index 69fd806753..1f41948d6d 100644 --- a/src/Symfony/Component/Serializer/Annotation/MaxDepth.php +++ b/src/Symfony/Component/Serializer/Annotation/MaxDepth.php @@ -30,8 +30,8 @@ class MaxDepth public function __construct(array $data) { - if (!isset($data['value']) || !$data['value']) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this))); + if (!isset($data['value'])) { + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', get_class($this))); } if (!is_int($data['value']) || $data['value'] <= 0) { diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php index 5594cb5f1b..d281c1d269 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php @@ -20,26 +20,32 @@ class MaxDepthTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException + * @expectedExceptionMessage Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" should be set. */ public function testNotSetMaxDepthParameter() { new MaxDepth(array()); } - /** - * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException - */ - public function testEmptyMaxDepthParameter() + public function provideInvalidValues() { - new MaxDepth(array('value' => '')); + return array( + array(''), + array('foo'), + array('1'), + array(0), + ); } /** + * @dataProvider provideInvalidValues + * * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException + * @expectedExceptionMessage Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer. */ - public function testNotAnIntMaxDepthParameter() + public function testNotAnIntMaxDepthParameter($value) { - new MaxDepth(array('value' => 'foo')); + new MaxDepth(array('value' => $value)); } public function testMaxDepthParameters()