Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DoctrineBridge] added missing error code for constraint. #19309

Merged
merged 1 commit into from Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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