|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;
|
13 | 13 |
|
| 14 | +use Doctrine\Common\Collections\ArrayCollection; |
14 | 15 | use Doctrine\Common\Persistence\ManagerRegistry;
|
15 | 16 | use Doctrine\Common\Persistence\ObjectManager;
|
16 | 17 | use Doctrine\Common\Persistence\ObjectRepository;
|
@@ -330,6 +331,44 @@ public function testValidateUniquenessWithUnrewoundArray()
|
330 | 331 | $this->assertNoViolation();
|
331 | 332 | }
|
332 | 333 |
|
| 334 | + /** |
| 335 | + * @dataProvider resultTypesProvider |
| 336 | + */ |
| 337 | + public function testValidateResultTypes($entity1, $result) |
| 338 | + { |
| 339 | + $constraint = new UniqueEntity(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 | + public function resultTypesProvider() |
| 362 | + { |
| 363 | + $entity = new SingleIntIdEntity(1, 'foo'); |
| 364 | + |
| 365 | + return array( |
| 366 | + array($entity, array($entity)), |
| 367 | + array($entity, new \ArrayIterator(array($entity))), |
| 368 | + array($entity, new ArrayCollection(array($entity))), |
| 369 | + ); |
| 370 | + } |
| 371 | + |
333 | 372 | public function testAssociatedEntity()
|
334 | 373 | {
|
335 | 374 | $constraint = new UniqueEntity(array(
|
|
0 commit comments