bug #15126 [2.6][Validator] Fix BC for Validator's validate method (michalmarcinkowski)

This PR was merged into the 2.6 branch.

Discussion
----------

[2.6][Validator] Fix BC for Validator's validate method

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This fix makes method call ``` $validator->validate($value, array()); ``` backward compatible and does not throw

```
[Symfony\Component\Validator\Exception\NoSuchMetadataException]

The class or interface "XXX" does not exist.
```

when the ``` $value ``` is a scalar type.

Commits
-------

ffe25dc [2.6][Validator] Fix BC for Validator's validate method
This commit is contained in:
Fabien Potencier 2015-06-28 19:09:43 +02:00
commit 6e4563e7ee
2 changed files with 7 additions and 1 deletions

View File

@ -75,6 +75,12 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
$this->assertCount(1, $violations);
}
public function testValidateWithEmptyArrayAsConstraint()
{
$violations = $this->validator->validate('value', array());
$this->assertCount(0, $violations);
}
public function testGroupSequenceAbortsAfterFailedGroup()
{
$entity = new Entity();

View File

@ -69,7 +69,7 @@ class LegacyValidator extends RecursiveValidator implements LegacyValidatorInter
private static function testConstraints($constraints)
{
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && current($constraints) instanceof Constraint);
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && (0 === count($constraints) || current($constraints) instanceof Constraint));
}
private static function testGroups($groups)