merged branch xabbuh/issue6651 (PR #7906)
This PR was squashed before being merged into the 2.1 branch (closes #7906).
Discussion
----------
if the repository method returns an array ensure that it's internal poin...
...ter is resetted
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #6651
| License | MIT
| Doc PR |
Commits
-------
0610750
if the repository method returns an array ensure that it's internal poin...
This commit is contained in:
commit
795e828140
@ -294,6 +294,31 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
||||
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
||||
}
|
||||
|
||||
public function testValidateUniquenessWithUnrewoundArray()
|
||||
{
|
||||
$entity = new SingleIdentEntity(1, 'foo');
|
||||
|
||||
$entityManagerName = 'foo';
|
||||
$repository = $this->createRepositoryMock();
|
||||
$repository->expects($this->once())
|
||||
->method('findByCustom')
|
||||
->will(
|
||||
$this->returnCallback(function() use ($entity) {
|
||||
$returnValue = array(
|
||||
$entity,
|
||||
);
|
||||
next($returnValue);
|
||||
return $returnValue;
|
||||
})
|
||||
)
|
||||
;
|
||||
$em = $this->createEntityManagerMock($repository);
|
||||
$validator = $this->createValidator($entityManagerName, $em, null, array(), null, 'findByCustom');
|
||||
|
||||
$violationsList = $validator->validate($entity);
|
||||
$this->assertCount(0, $violationsList, 'Violation is using unrewound array as return value in the repository method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group GH-1635
|
||||
*/
|
||||
|
@ -108,6 +108,8 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
*/
|
||||
if ($result instanceof \Iterator) {
|
||||
$result->rewind();
|
||||
} elseif (is_array($result)) {
|
||||
reset($result);
|
||||
}
|
||||
|
||||
/* If no entity matched the query criteria or a single entity matched,
|
||||
|
Reference in New Issue
Block a user