bug #12031 [Validator] Fixed LegacyValidator when only a constraint is validated (webmozart)

This PR was merged into the 2.5 branch.

Discussion
----------

[Validator] Fixed LegacyValidator when only a constraint is validated

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

The 2.5-BC API is currently broken for the following use case:

```php
$validator->validate($value, $constraint);
```

This is fixed now.

Commits
-------

1d48206 [Validator] Fixed LegacyValidator when only a constraint is validated
This commit is contained in:
Fabien Potencier 2014-09-25 15:54:04 +02:00
commit 07b234e1c7
2 changed files with 9 additions and 1 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Tests\Validator;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Traverse;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintViolationInterface;
@ -66,6 +67,13 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
return $this->validator->validatePropertyValue($object, $propertyName, $value, $groups);
}
public function testValidateConstraintWithoutGroup()
{
$violations = $this->validator->validate(null, new NotNull());
$this->assertCount(1, $violations);
}
public function testGroupSequenceAbortsAfterFailedGroup()
{
$entity = new Entity();

View File

@ -44,7 +44,7 @@ class LegacyValidator extends RecursiveValidator implements LegacyValidatorInter
$numArgs = func_num_args();
// Use new signature if constraints are given in the second argument
if (self::testConstraints($groups) && ($numArgs < 2 || 3 === $numArgs && self::testGroups($traverse))) {
if (self::testConstraints($groups) && ($numArgs < 3 || 3 === $numArgs && self::testGroups($traverse))) {
// Rename to avoid total confusion ;)
$constraints = $groups;
$groups = $traverse;