Skip to content

Commit eceea88

Browse files
Merge branch '2.8' into 3.0
* 2.8: [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 Conflicts: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
2 parents 3c4c0a8 + aafe1de commit eceea88

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
@@ -161,6 +161,7 @@ public function testValidateUniqueness()
161161
$this->buildViolation('myMessage')
162162
->atPath('property.path.name')
163163
->setInvalidValue('Foo')
164+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
164165
->assertRaised();
165166
}
166167

@@ -184,6 +185,7 @@ public function testValidateCustomErrorPath()
184185
$this->buildViolation('myMessage')
185186
->atPath('property.path.bar')
186187
->setInvalidValue('Foo')
188+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
187189
->assertRaised();
188190
}
189191

@@ -235,6 +237,7 @@ public function testValidateUniquenessWithIgnoreNull()
235237
$this->buildViolation('myMessage')
236238
->atPath('property.path.name')
237239
->setInvalidValue('Foo')
240+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
238241
->assertRaised();
239242
}
240243

@@ -266,6 +269,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
266269
$this->buildViolation('myMessage')
267270
->atPath('property.path.name2')
268271
->setInvalidValue('Bar')
272+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
269273
->assertRaised();
270274
}
271275

@@ -398,6 +402,7 @@ public function testAssociatedEntity()
398402
$this->buildViolation('myMessage')
399403
->atPath('property.path.single')
400404
->setInvalidValue($entity1)
405+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
401406
->assertRaised();
402407
}
403408

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
@@ -130,6 +130,7 @@ public function validate($entity, Constraint $constraint)
130130
$this->context->buildViolation($constraint->message)
131131
->atPath($errorPath)
132132
->setInvalidValue($invalidValue)
133+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
133134
->addViolation();
134135
}
135136
}

0 commit comments

Comments
 (0)