Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8d3ef7

Browse files
committed
bug #19309 [DoctrineBridge] added missing error code for constraint. (Koc)
This PR was merged into the 2.8 branch. Discussion ---------- [DoctrineBridge] added missing error code for constraint. | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | wait for travis | Fixed tickets | #15154 | License | MIT | Doc PR | - Commits ------- 32cb269 [DoctrineBridge] added missing error code for constraint.
2 parents 1f70837 + 32cb269 commit f8d3ef7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function testValidateUniqueness()
167167
$this->buildViolation('myMessage')
168168
->atPath('property.path.name')
169169
->setInvalidValue('Foo')
170+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
170171
->assertRaised();
171172
}
172173

@@ -190,6 +191,7 @@ public function testValidateCustomErrorPath()
190191
$this->buildViolation('myMessage')
191192
->atPath('property.path.bar')
192193
->setInvalidValue('Foo')
194+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
193195
->assertRaised();
194196
}
195197

@@ -241,6 +243,7 @@ public function testValidateUniquenessWithIgnoreNull()
241243
$this->buildViolation('myMessage')
242244
->atPath('property.path.name')
243245
->setInvalidValue('Foo')
246+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
244247
->assertRaised();
245248
}
246249

@@ -272,6 +275,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
272275
$this->buildViolation('myMessage')
273276
->atPath('property.path.name2')
274277
->setInvalidValue('Bar')
278+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
275279
->assertRaised();
276280
}
277281

@@ -404,6 +408,7 @@ public function testAssociatedEntity()
404408
$this->buildViolation('myMessage')
405409
->atPath('property.path.single')
406410
->setInvalidValue($entity1)
411+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
407412
->assertRaised();
408413
}
409414

src/Symfony/Bridge/Doctrine/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');

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ public function validate($entity, Constraint $constraint)
132132
$this->context->buildViolation($constraint->message)
133133
->atPath($errorPath)
134134
->setInvalidValue($invalidValue)
135+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
135136
->addViolation();
136137
} else {
137138
$this->buildViolation($constraint->message)
138139
->atPath($errorPath)
139140
->setInvalidValue($invalidValue)
141+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
140142
->addViolation();
141143
}
142144
}

0 commit comments

Comments
 (0)