Skip to content

Commit

Permalink
bug #19309 [DoctrineBridge] added missing error code for constraint. …
Browse files Browse the repository at this point in the history
…(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.
  • Loading branch information
fabpot committed Jul 8, 2016
2 parents 1f70837 + 32cb269 commit f8d3ef7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Expand Up @@ -167,6 +167,7 @@ public function testValidateUniqueness()
$this->buildViolation('myMessage')
->atPath('property.path.name')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

Expand All @@ -190,6 +191,7 @@ public function testValidateCustomErrorPath()
$this->buildViolation('myMessage')
->atPath('property.path.bar')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

Expand Down Expand Up @@ -241,6 +243,7 @@ public function testValidateUniquenessWithIgnoreNull()
$this->buildViolation('myMessage')
->atPath('property.path.name')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

Expand Down Expand Up @@ -272,6 +275,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
$this->buildViolation('myMessage')
->atPath('property.path.name2')
->setInvalidValue('Bar')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

Expand Down Expand Up @@ -404,6 +408,7 @@ public function testAssociatedEntity()
$this->buildViolation('myMessage')
->atPath('property.path.single')
->setInvalidValue($entity1)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

Expand Down
Expand Up @@ -23,6 +23,8 @@
*/
class UniqueEntity extends Constraint
{
const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';

public $message = 'This value is already used.';
public $service = 'doctrine.orm.validator.unique';
public $em = null;
Expand All @@ -31,6 +33,10 @@ class UniqueEntity extends Constraint
public $errorPath = null;
public $ignoreNull = true;

protected static $errorNames = array(
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
);

public function getRequiredOptions()
{
return array('fields');
Expand Down
Expand Up @@ -132,11 +132,13 @@ public function validate($entity, Constraint $constraint)
$this->context->buildViolation($constraint->message)
->atPath($errorPath)
->setInvalidValue($invalidValue)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->addViolation();
} else {
$this->buildViolation($constraint->message)
->atPath($errorPath)
->setInvalidValue($invalidValue)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->addViolation();
}
}
Expand Down

0 comments on commit f8d3ef7

Please sign in to comment.