Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa9801e

Browse files
committed
bug#17078 [Bridge] [Doctrine] [Validator] Added support \IteratorAggregate for UniqueEntityValidator (Disparity)
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes#17078).Discussion----------[Bridge] [Doctrine] [Validator] Added support \IteratorAggregate for UniqueEntityValidator| Q | A| ------------- | ---| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |Expand the list of supported types of results returned from the repositories.Added processing of type \IteratorAggregate (and as a consequence doctrine Collection)Commits-------6ebd179 Added support \IteratorAggregate for UniqueEntityValidator
2 parents5d63c55 +6ebd179 commitaa9801e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

‎src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Bridge\Doctrine\Tests\Validator\Constraints;
1313

14+
useDoctrine\Common\Collections\ArrayCollection;
1415
useDoctrine\Common\Persistence\ManagerRegistry;
1516
useDoctrine\Common\Persistence\ObjectManager;
1617
useDoctrine\Common\Persistence\ObjectRepository;
@@ -330,6 +331,44 @@ public function testValidateUniquenessWithUnrewoundArray()
330331
$this->assertNoViolation();
331332
}
332333

334+
/**
335+
* @dataProvider resultTypesProvider
336+
*/
337+
publicfunctiontestValidateResultTypes($entity1,$result)
338+
{
339+
$constraint =newUniqueEntity(array(
340+
'message' =>'myMessage',
341+
'fields' =>array('name'),
342+
'em' =>self::EM_NAME,
343+
'repositoryMethod' =>'findByCustom',
344+
));
345+
346+
$repository =$this->createRepositoryMock();
347+
$repository->expects($this->once())
348+
->method('findByCustom')
349+
->will($this->returnValue($result))
350+
;
351+
$this->em =$this->createEntityManagerMock($repository);
352+
$this->registry =$this->createRegistryMock($this->em);
353+
$this->validator =$this->createValidator();
354+
$this->validator->initialize($this->context);
355+
356+
$this->validator->validate($entity1,$constraint);
357+
358+
$this->assertNoViolation();
359+
}
360+
361+
publicfunctionresultTypesProvider()
362+
{
363+
$entity =newSingleIntIdEntity(1,'foo');
364+
365+
returnarray(
366+
array($entity,array($entity)),
367+
array($entity,new \ArrayIterator(array($entity))),
368+
array($entity,newArrayCollection(array($entity))),
369+
);
370+
}
371+
333372
publicfunctiontestAssociatedEntity()
334373
{
335374
$constraint =newUniqueEntity(array(

‎src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function validate($entity, Constraint $constraint)
109109
$repository =$em->getRepository(get_class($entity));
110110
$result =$repository->{$constraint->repositoryMethod}($criteria);
111111

112+
if ($resultinstanceof \IteratorAggregate) {
113+
$result =$result->getIterator();
114+
}
115+
112116
/* If the result is a MongoCursor, it must be advanced to the first
113117
* element. Rewinding should have no ill effect if $result is another
114118
* iterator implementation.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp