[DoctrineBridge] added missing error code for constraint.
This commit is contained in:
parent
1f7083764a
commit
32cb269614
@ -167,6 +167,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.name')
|
->atPath('property.path.name')
|
||||||
->setInvalidValue('Foo')
|
->setInvalidValue('Foo')
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +191,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.bar')
|
->atPath('property.path.bar')
|
||||||
->setInvalidValue('Foo')
|
->setInvalidValue('Foo')
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +243,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.name')
|
->atPath('property.path.name')
|
||||||
->setInvalidValue('Foo')
|
->setInvalidValue('Foo')
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +275,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.name2')
|
->atPath('property.path.name2')
|
||||||
->setInvalidValue('Bar')
|
->setInvalidValue('Bar')
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +408,7 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.single')
|
->atPath('property.path.single')
|
||||||
->setInvalidValue($entity1)
|
->setInvalidValue($entity1)
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ use Symfony\Component\Validator\Constraint;
|
|||||||
*/
|
*/
|
||||||
class UniqueEntity extends Constraint
|
class UniqueEntity extends Constraint
|
||||||
{
|
{
|
||||||
|
const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
|
||||||
|
|
||||||
public $message = 'This value is already used.';
|
public $message = 'This value is already used.';
|
||||||
public $service = 'doctrine.orm.validator.unique';
|
public $service = 'doctrine.orm.validator.unique';
|
||||||
public $em = null;
|
public $em = null;
|
||||||
@ -31,6 +33,10 @@ class UniqueEntity extends Constraint
|
|||||||
public $errorPath = null;
|
public $errorPath = null;
|
||||||
public $ignoreNull = true;
|
public $ignoreNull = true;
|
||||||
|
|
||||||
|
protected static $errorNames = array(
|
||||||
|
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
|
||||||
|
);
|
||||||
|
|
||||||
public function getRequiredOptions()
|
public function getRequiredOptions()
|
||||||
{
|
{
|
||||||
return array('fields');
|
return array('fields');
|
||||||
|
@ -132,11 +132,13 @@ class UniqueEntityValidator extends ConstraintValidator
|
|||||||
$this->context->buildViolation($constraint->message)
|
$this->context->buildViolation($constraint->message)
|
||||||
->atPath($errorPath)
|
->atPath($errorPath)
|
||||||
->setInvalidValue($invalidValue)
|
->setInvalidValue($invalidValue)
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
} else {
|
} else {
|
||||||
$this->buildViolation($constraint->message)
|
$this->buildViolation($constraint->message)
|
||||||
->atPath($errorPath)
|
->atPath($errorPath)
|
||||||
->setInvalidValue($invalidValue)
|
->setInvalidValue($invalidValue)
|
||||||
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user