8000 wip · symfony/symfony@7b08244 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b08244

Browse files
committed
wip
1 parent d04c0ea commit 7b08244

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Validator\Tests\Fixtures;
4+
5+
class Timer
6+
{
7+
private $duration;
8+
9+
public function __construct($duration)
10+
{
11+
$this->duration = $duration;
12+
}
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symfony\Component\Validator\Test 10000 s\Fixtures;
4+
5+
class TimerCollection implements \IteratorAggregate
6+
{
7+
/**
8+
* @var array
9+
*/
10+
private $timers;
11+
12+
/**
13+
* @param Timer[] $timers
14+
*/
15+
public function __construct(array $timers)
16+
{
17+
$this->timers = $timers;
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function getIterator()
24+
{
25+
return new \ArrayIterator($this->timers);
26+
}
27+
}

src/Symfony/Component/Validator/Tests/LegacyExecutionContextTest.php

Lines changed: 26 additions & 0 deletions
< 10000 /tr>
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Validator\Tests;
1313

14+
use Symfony\Component\Validator\Constraints\NotBlank;
15+
use Symfony\Component\Validator\Tests\Fixtures\Aggregate;
1416
use PHPUnit\Framework\TestCase;
1517
use Symfony\Component\Validator\Constraints\Collection;
1618
use Symfony\Component\Validator\Constraints\All;
@@ -19,6 +21,9 @@
1921
use Symfony\Component\Validator\ConstraintViolationList;
2022
use Symfony\Component\Validator\ExecutionContext;
2123
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
24+
use Symfony\Component\Validator\Tests\Fixtures\Timer;
25+
use Symfony\Component\Validator\Tests\Fixtures\TimerCollection;
26+
use Symfony\Component\Validator\Validation;
2227
use Symfony\Component\Validator\ValidationVisitor;
2328

2429
/**
@@ -327,6 +332,27 @@ public function testGetPropertyPathWithNestedCollectionsAndAllMixed()
327332

328333
$this->assertEquals($expectedViolationPaths, $violationPaths);
329334
}
335+
336+
public function testGetPropertyPathWithNestedCollectionsAndAllMixedWithIteratorAggregate()
337+
{
338+
$data = new TimerCollection(array(
339+
new Timer(null),
340+
new Timer('PT10M'),
341+
new Timer(null),
342+
));
343+
344+
$validator = Validation::createValidatorBuilder()->getValidator();
345+
$metadata = $validator->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\Timer');
346+
$metadata->addPropertyConstraint('duration', new NotBlank());
347+
348+
$violationPaths = [];
349+
350+
foreach ($validator->validate($data) as $violation) {
351+
$violationPaths[] = $violation->getPropertyPath();
352+
}
353+
354+
$this->assertSame(array('[0].duration', '[2].duration'), $violationPaths);
355+
}
330356
}
331357

332358
class ExecutionContextTest_TestClass

src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,10 @@ private function validateGenericNode($value, $object, $cacheKey, MetadataInterfa
748748
// See validateClassNode()
749749
$cascadedGroups = null !== $cascadedGroups && count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
750750

751+
// if (is_array($value) || $value instanceof \IteratorAggregate) {
751752
if (is_array($value)) {
752-
// Arrays are always traversed, independent of the specified
753-
// traversal strategy
753+
// Arrays and instance of IteratorAggregate are always traversed, independent of the
754+
// specified traversal strategy
754755
// (BC with Symfony < 2.5)
755756
$this->validateEachObjectIn(
756757
$value,

0 commit comments

Comments
 (0)
0