|
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;
|
@@ -137,6 +138,16 @@ private function createSchema(ObjectManager $em)
|
137 | 138 | ));
|
138 | 139 | }
|
139 | 140 |
|
| 141 | + public function resultTypesProvider() |
| 142 | + { |
| 143 | + $entity = new SingleIntIdEntity(1, 'foo'); |
| 144 | + return array( |
| 145 | + array($entity, array($entity)), |
| 146 | + array($entity, new \ArrayIterator(array($entity))), |
| 147 | + array($entity, new ArrayCollection(array($entity))), |
| 148 | + ); |
| 149 | + } |
| 150 | + |
140 | 151 | /**
|
141 | 152 | * This is a functional test as there is a large integration necessary to get the validator working.
|
142 | 153 | */
|
@@ -336,6 +347,33 @@ public function testValidateUniquenessWithUnrewoundArray()
|
336 | 347 | $this->assertNoViolation();
|
337 | 348 | }
|
338 | 349 |
|
| 350 | + /** |
| 351 | + * @dataProvider resultTypesProvider |
| 352 | + */ |
| 353 | + public function testValidateResultTypes($entity1, $result) |
| 354 | + { |
| 355 | + $constraint = new UniqueEntity(array( |
| 356 | + 'message' => 'myMessage', |
| 357 | + 'fields' => array('name'), |
| 358 | + 'em' => self::EM_NAME, |
| 359 | + 'repositoryMethod' => 'findByCustom', |
| 360 | + )); |
| 361 | + |
| 362 | + $repository = $this->createRepositoryMock(); |
| 363 | + $repository->expects($this->once()) |
| 364 | + ->method('findByCustom') |
| 365 | + ->will($this->returnValue($result)) |
| 366 | + ; |
| 367 | + $this->em = $this->createEntityManagerMock($repository); |
| 368 | + $this->registry = $this->createRegistryMock($this->em); |
| 369 | + $this->validator = $this->createValidator(); |
| 370 | + $this->validator->initialize($this->context); |
| 371 | + |
| 372 | + $this->validator->validate($entity1, $constraint); |
| 373 | + |
| 374 | + $this->assertNoViolation(); |
| 375 | + } |
| 376 | + |
339 | 377 | public function testAssociatedEntity()
|
340 | 378 | {
|
341 | 379 | $constraint = new UniqueEntity(array(
|
|
0 commit comments