Skip to content

Commit 978a13b

Browse files
committed
minor symfony#20945 [Serializer] Fix MaxDepth annotation exceptions (ogizanagi)
This PR was merged into the 3.1 branch. Discussion ---------- [Serializer] Fix MaxDepth annotation exceptions | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yesish (rather improving existing DX, the exception message is not always the most relevant) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A I'd suggest to slightly change the `MaxDepth` value checks, as for instance setting a 0 value throws the following exception: > Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" cannot be empty. where we should rather expect: > Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer. IMHO we could even keep the last one only, even if no value has been provided. Commits ------- 999f769 [Serializer] Fix MaxDepth annotation exceptions
2 parents 05e83f5 + 999f769 commit 978a13b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Symfony/Component/Serializer/Annotation/MaxDepth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class MaxDepth
3030

3131
public function __construct(array $data)
3232
{
33-
if (!isset($data['value']) || !$data['value']) {
34-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this)));
33+
if (!isset($data['value'])) {
34+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" should be set.', get_class($this)));
3535
}
3636

3737
if (!is_int($data['value']) || $data['value'] <= 0) {

src/Symfony/Component/Serializer/Tests/Annotation/MaxDepthTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,32 @@ class MaxDepthTest extends \PHPUnit_Framework_TestCase
2020
{
2121
/**
2222
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
23+
* @expectedExceptionMessage Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" should be set.
2324
*/
2425
public function testNotSetMaxDepthParameter()
2526
{
2627
new MaxDepth(array());
2728
}
2829

29-
/**
30-
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
31-
*/
32-
public function testEmptyMaxDepthParameter()
30+
public function provideInvalidValues()
3331
{
34-
new MaxDepth(array('value' => ''));
32+
return array(
33+
array(''),
34+
array('foo'),
35+
array('1'),
36+
array(0),
37+
);
3538
}
3639

3740
/**
41+
* @dataProvider provideInvalidValues
42+
*
3843
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
44+
* @expectedExceptionMessage Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer.
3945
*/
40-
public function testNotAnIntMaxDepthParameter()
46+
public function testNotAnIntMaxDepthParameter($value)
4147
{
42-
new MaxDepth(array('value' => 'foo'));
48+
new MaxDepth(array('value' => $value));
4349
}
4450

4551
public function testMaxDepthParameters()

0 commit comments

Comments
 (0)