Skip to content

Commit ea6c4e8

Browse files
Merge branch '3.4'
* 3.4: (26 commits) [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit [Console] Fix disabling lazy commands [DI] Remove scalar typehint in class used in test case Remove the `server:log` command if monolog is not loaded [SecurityBundle] Fix syntax error in test [Console] Remove remaining dead code Throw on service:method factory notation in PHP-based DI configuration Test that named arguments are prioritized over typehinted bumped Symfony version to 3.3.14 bumped Symfony version to 2.8.32 bumped Symfony version to 2.7.39 Prove that change is working with tests updated VERSION for 3.3.13 updated CHANGELOG for 3.3.13 updated VERSION for 2.8.31 updated CHANGELOG for 2.8.31 updated VERSION for 2.7.38 updated CHANGELOG for 2.7.38 Replace array|\Traversable by iterable [DI] Fix by-type args injection ...
2 parents b48c737 + 6641e87 commit ea6c4e8

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UrlValidator extends ConstraintValidator
2525
(%s):// # protocol
2626
(([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth
2727
(
28-
([\pL\pN\pS-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
28+
([\pL\pN\pS\-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
2929
| # or
3030
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
3131
| # or

Constraints/ValidValidator.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ public function validate($value, Constraint $constraint)
2626
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid');
2727
}
2828

29-
$violations = $this->context->getValidator()->validate($value, null, array($this->context->getGroup()));
30-
31-
foreach ($violations as $violation) {
32-
$this->context->buildViolation($violation->getMessage(), $violation->getParameters())
33-
->atPath($violation->getPropertyPath())
34-
->addViolation();
35-
}
29+
$this->context
30+
->getValidator()
31+
->inContext($this->context)
32+
->validate($value, null, array($this->context->getGroup()));
3633
}
3734
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Symfony\Component\Validator\Tests\Constraints;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
use Symfony\Component\Validator\Constraints\ValidValidator;
8+
use Symfony\Component\Validator\ValidatorBuilder;
9+
10+
class ValidValidatorTest extends TestCase
11+
{
12+
public function testPropertyPathsArePassedToNestedContexts()
13+
{
14+
$validatorBuilder = new ValidatorBuilder();
15+
$validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
16+
17+
$violations = $validator->validate(new Foo(), null, array('nested'));
18+
19+
$this->assertCount(1, $violations);
20+
$this->assertSame('fooBar.fooBarBaz.foo', $violations->get(0)->getPropertyPath());
21+
}
22+
23+
protected function createValidator()
24+
{
25+
return new ValidValidator();
26+
}
27+
}
28+
29+
class Foo
30+
{
31+
/**
32+
* @Assert\Valid(groups={"nested"})
33+
*/
34+
public $fooBar;
35+
36+
public function __construct()
37+
{
38+
$this->fooBar = new FooBar();
39+
}
40+
}
41+
42+
class FooBar
43+
{
44+
/**
45+
* @Assert\Valid(groups={"nested"})
46+
*/
47+
public $fooBarBaz;
48+
49+
public function __construct()
50+
{
51+
$this->fooBarBaz = new FooBarBaz();
52+
}
53+
}
54+
55+
class FooBarBaz
56+
{
57+
/**
58+
* @Assert\NotBlank(groups={"nested"})
59+
*/
60+
public $foo;
61+
}

Validator/RecursiveContextualValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private function validateObject($object, $propertyPath, array $groups, $traversa
374374
* objects are iterated as well. Nested arrays are always iterated,
375375
* regardless of the value of $recursive.
376376
*
377-
* @param array|\Traversable $collection The collection
377+
* @param iterable $collection The collection
378378
* @param string $propertyPath The current property path
379379
* @param string[] $groups The validated groups
380380
* @param ExecutionContextInterface $context The current execution context

0 commit comments

Comments
 (0)