if the repository method returns an array ensure that it's internal poin...
This commit is contained in:
parent
030695752b
commit
0610750378
@ -294,6 +294,31 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
$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
|
* @group GH-1635
|
||||||
*/
|
*/
|
||||||
|
@ -108,6 +108,8 @@ class UniqueEntityValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
if ($result instanceof \Iterator) {
|
if ($result instanceof \Iterator) {
|
||||||
$result->rewind();
|
$result->rewind();
|
||||||
|
} elseif (is_array($result)) {
|
||||||
|
reset($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no entity matched the query criteria or a single entity matched,
|
/* If no entity matched the query criteria or a single entity matched,
|
||||||
|
Reference in New Issue
Block a user