Skip to content

Commit 327e9c9

Browse files
Merge branch '3.1'
* 3.1: [HttpKernel] fixed internal subrequests having an if-modified-since-header [Security] Fix deprecated usage of DigestAuthenticationEntryPoint::getKey() in DigestAuthenticationListener [Validator] Added additional MasterCard range to the CardSchemeValidator Make the exception message more clear. [Form] fixed bug - name in ButtonBuilder [DoctrineBridge] added missing error code for constraint. [ClassLoader] Fix declared classes being computed when not needed [varDumper] Fix missing usage of ExceptionCaster::$traceArgs
2 parents 88b4faf + 632b5c5 commit 327e9c9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function testValidateUniqueness()
168168
->atPath('property.path.name')
169169
->setParameter('{{ value }}', 'Foo')
170170
->setInvalidValue('Foo')
171+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
171172
->assertRaised();
172173
}
173174

@@ -192,6 +193,7 @@ public function testValidateCustomErrorPath()
192193
->atPath('property.path.bar')
193194
->setParameter('{{ value }}', 'Foo')
194195
->setInvalidValue('Foo')
196+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
195197
->assertRaised();
196198
}
197199

@@ -244,6 +246,7 @@ public function testValidateUniquenessWithIgnoreNull()
244246
->atPath('property.path.name')
245247
->setParameter('{{ value }}', 'Foo')
246248
->setInvalidValue('Foo')
249+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
247250
->assertRaised();
248251
}
249252

@@ -276,6 +279,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
276279
->atPath('property.path.name2')
277280
->setParameter('{{ value }}', 'Bar')
278281
->setInvalidValue('Bar')
282+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
279283
->assertRaised();
280284
}
281285

@@ -409,6 +413,7 @@ public function testAssociatedEntity()
409413
->atPath('property.path.single')
410414
->setParameter('{{ value }}', $entity1)
411415
->setInvalidValue($entity1)
416+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
412417
->assertRaised();
413418
}
414419

Validator/Constraints/UniqueEntity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class UniqueEntity extends Constraint
2525
{
26+
const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
27+
2628
public $message = 'This value is already used.';
2729
public $service = 'doctrine.orm.validator.unique';
2830
public $em = null;
@@ -31,6 +33,10 @@ class UniqueEntity extends Constraint
3133
public $errorPath = null;
3234
public $ignoreNull = true;
3335

36+
protected static $errorNames = array(
37+
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
38+
);
39+
3440
public function getRequiredOptions()
3541
{
3642
return array('fields');

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public function validate($entity, Constraint $constraint)
135135
->atPath($errorPath)
136136
->setParameter('{{ value }}', $invalidValue)
137137
->setInvalidValue($invalidValue)
138+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
138139
->addViolation();
139140
}
140141
}

0 commit comments

Comments
 (0)