class ConstraintViolationAssertion in Plug 7
@internal
Hierarchy
- class \Symfony\Component\Validator\Tests\Constraints\ConstraintViolationAssertion
Expanded class hierarchy of ConstraintViolationAssertion
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Tests/ Constraints/ AbstractConstraintValidatorTest.php, line 416
Namespace
Symfony\Component\Validator\Tests\ConstraintsView source
class ConstraintViolationAssertion {
/**
* @var LegacyExecutionContextInterface
*/
private $context;
/**
* @var ConstraintViolationAssertion[]
*/
private $assertions;
private $message;
private $parameters = array();
private $invalidValue = 'InvalidValue';
private $propertyPath = 'property.path';
private $translationDomain;
private $plural;
private $code;
private $constraint;
private $cause;
public function __construct(LegacyExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array()) {
$this->context = $context;
$this->message = $message;
$this->constraint = $constraint;
$this->assertions = $assertions;
}
public function atPath($path) {
$this->propertyPath = $path;
return $this;
}
public function setParameter($key, $value) {
$this->parameters[$key] = $value;
return $this;
}
public function setParameters(array $parameters) {
$this->parameters = $parameters;
return $this;
}
public function setTranslationDomain($translationDomain) {
$this->translationDomain = $translationDomain;
return $this;
}
public function setInvalidValue($invalidValue) {
$this->invalidValue = $invalidValue;
return $this;
}
public function setPlural($number) {
$this->plural = $number;
return $this;
}
public function setCode($code) {
$this->code = $code;
return $this;
}
public function setCause($cause) {
$this->cause = $cause;
return $this;
}
public function buildNextViolation($message) {
$assertions = $this->assertions;
$assertions[] = $this;
return new self($this->context, $message, $this->constraint, $assertions);
}
public function assertRaised() {
$expected = array();
foreach ($this->assertions as $assertion) {
$expected[] = $assertion
->getViolation();
}
$expected[] = $this
->getViolation();
$violations = iterator_to_array($this->context
->getViolations());
\PHPUnit_Framework_Assert::assertCount(count($expected), $violations);
reset($violations);
foreach ($expected as $violation) {
\PHPUnit_Framework_Assert::assertEquals($violation, current($violations));
next($violations);
}
}
private function getViolation() {
return new ConstraintViolation(null, $this->message, $this->parameters, $this->context
->getRoot(), $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause);
}
}