[DoctrineBridge] added missing error code for constraint.

This commit is contained in:
Konstantin.Myakshin 2016-07-07 18:14:45 +03:00
parent 1f7083764a
commit 32cb269614
3 changed files with 13 additions and 0 deletions

View File

@ -167,6 +167,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
$this->buildViolation('myMessage')
->atPath('property.path.name')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}
@ -190,6 +191,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
$this->buildViolation('myMessage')
->atPath('property.path.bar')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}
@ -241,6 +243,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
$this->buildViolation('myMessage')
->atPath('property.path.name')
->setInvalidValue('Foo')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}
@ -272,6 +275,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
$this->buildViolation('myMessage')
->atPath('property.path.name2')
->setInvalidValue('Bar')
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}
@ -404,6 +408,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
$this->buildViolation('myMessage')
->atPath('property.path.single')
->setInvalidValue($entity1)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->assertRaised();
}

View File

@ -23,6 +23,8 @@ use Symfony\Component\Validator\Constraint;
*/
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;
@ -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');

View File

@ -132,11 +132,13 @@ class UniqueEntityValidator extends ConstraintValidator
$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();
}
}