Skip to content

Commit

Permalink
[Validator] don't trigger deprecation with empty group array
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 26, 2015
1 parent a0af4ef commit 62f12cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Validator\RecursiveValidator;

class RecursiveValidator2Dot5ApiTest extends Abstract2Dot5ApiTest
Expand All @@ -29,4 +30,28 @@ protected function createValidator(MetadataFactoryInterface $metadataFactory, ar

return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $objectInitializers);
}

public function testEmptyGroupsArrayDoesNotTriggerDeprecation()
{
$entity = new Entity();

$validatorContext = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
$validatorContext
->expects($this->once())
->method('validate')
->with($entity, null, array())
->willReturnSelf();

$validator = $this
->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
->disableOriginalConstructor()
->setMethods(array('startContext'))
->getMock();
$validator
->expects($this->once())
->method('startContext')
->willReturn($validatorContext);

$validator->validate($entity, null, array());
}
}
Expand Up @@ -25,6 +25,7 @@
* Recursive implementation of {@link ValidatorInterface}.
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RecursiveValidator implements ValidatorInterface, LegacyValidatorInterface
Expand Down Expand Up @@ -182,6 +183,6 @@ private static function testConstraints($constraints)

private static function testGroups($groups)
{
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence));
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (0 === count($groups) || is_string(current($groups)) || current($groups) instanceof GroupSequence));
}
}

0 comments on commit 62f12cd

Please sign in to comment.