[Serializer] Fix MaxDepth annotation exceptions

This commit is contained in:
Maxime Steinhausser 2016-12-15 20:58:01 +01:00
parent 05e83f5a4e
commit 999f769ba5
2 changed files with 15 additions and 9 deletions

View File

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

View File

@ -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()