Skip to content

Commit 8f86ba6

Browse files
committed
[Serializer] Fix MaxDepth annotation exceptions
1 parent f4b3093 commit 8f86ba6

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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) {

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)