|
18 | 18 | use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
19 | 19 | use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
20 | 20 | use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
|
| 21 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity; |
21 | 22 | use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
|
22 | 23 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
23 | 24 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
|
@@ -132,6 +133,7 @@ private function createSchema(ObjectManager $em)
|
132 | 133 | $schemaTool->createSchema(array(
|
133 | 134 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity'),
|
134 | 135 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity'),
|
| 136 | + $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity'), |
135 | 137 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'),
|
136 | 138 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'),
|
137 | 139 | ));
|
@@ -213,7 +215,7 @@ public function testValidateUniquenessWithNull()
|
213 | 215 | $this->assertNoViolation();
|
214 | 216 | }
|
215 | 217 |
|
216 |
| - public function testValidateUniquenessWithIgnoreNull() |
| 218 | + public function testValidateUniquenessWithIgnoreNullDisabled() |
217 | 219 | {
|
218 | 220 | $constraint = new UniqueEntity(array(
|
219 | 221 | 'message' => 'myMessage',
|
@@ -261,6 +263,34 @@ public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgno
|
261 | 263 | $this->validator->validate($entity1, $constraint);
|
262 | 264 | }
|
263 | 265 |
|
| 266 | + public function testNoValidationIfFirstFieldIsNullAndNullValuesAreIgnored() |
| 267 | + { |
| 268 | + $constraint = new UniqueEntity(array( |
| 269 | + 'message' => 'myMessage', |
| 270 | + 'fields' => array('name', 'name2'), |
| 271 | + 'em' => self::EM_NAME, |
| 272 | + 'ignoreNull' => true, |
| 273 | + )); |
| 274 | + |
| 275 | + $entity1 = new DoubleNullableNameEntity(1, null, 'Foo'); |
| 276 | + $entity2 = new DoubleNullableNameEntity(2, null, 'Foo'); |
| 277 | + |
| 278 | + $this->validator->validate($entity1, $constraint); |
| 279 | + |
| 280 | + $this->assertNoViolation(); |
| 281 | + |
| 282 | + $this->em->persist($entity1); |
| 283 | + $this->em->flush(); |
| 284 | + |
| 285 | + $this->validator->validate($entity1, $constraint); |
| 286 | + |
| 287 | + $this->assertNoViolation(); |
| 288 | + |
| 289 | + $this->validator->validate($entity2, $constraint); |
| 290 | + |
| 291 | + $this->assertNoViolation(); |
| 292 | + } |
| 293 | + |
264 | 294 | public function testValidateUniquenessWithValidCustomErrorPath()
|
265 | 295 | {
|
266 | 296 | $constraint = new UniqueEntity(array(
|
|
0 commit comments