class ConstraintViolationAssertion
Hierarchy
- class \Symfony\Component\Validator\Test\ConstraintViolationAssertion
Expanded class hierarchy of ConstraintViolationAssertion
File
-
vendor/
symfony/ validator/ Test/ ConstraintValidatorTestCase.php, line 296
Namespace
Symfony\Component\Validator\TestView source
final class ConstraintViolationAssertion {
private array $parameters = [];
private mixed $invalidValue = 'InvalidValue';
private string $propertyPath = 'property.path';
private ?int $plural = null;
private ?string $code = null;
private mixed $cause = null;
/**
* @param ConstraintViolationAssertion[] $assertions
*
* @internal
*/
public function __construct(ExecutionContextInterface $context, string $message, ?Constraint $constraint = null, array $assertions = []) {
}
/**
* @return $this
*/
public function atPath(string $path) : static {
$this->propertyPath = $path;
return $this;
}
/**
* @return $this
*/
public function setParameter(string $key, string $value) : static {
$this->parameters[$key] = $value;
return $this;
}
/**
* @return $this
*/
public function setParameters(array $parameters) : static {
$this->parameters = $parameters;
return $this;
}
/**
* @return $this
*/
public function setTranslationDomain(?string $translationDomain) : static {
// no-op for BC
return $this;
}
/**
* @return $this
*/
public function setInvalidValue(mixed $invalidValue) : static {
$this->invalidValue = $invalidValue;
return $this;
}
/**
* @return $this
*/
public function setPlural(int $number) : static {
$this->plural = $number;
return $this;
}
/**
* @return $this
*/
public function setCode(string $code) : static {
$this->code = $code;
return $this;
}
/**
* @return $this
*/
public function setCause(mixed $cause) : static {
$this->cause = $cause;
return $this;
}
public function buildNextViolation(string $message) : self {
$assertions = $this->assertions;
$assertions[] = $this;
return new self($this->context, $message, $this->constraint, $assertions);
}
public function assertRaised() : void {
$expected = [];
foreach ($this->assertions as $assertion) {
$expected[] = $assertion->getViolation();
}
$expected[] = $this->getViolation();
$violations = iterator_to_array($this->context
->getViolations());
Assert::assertSame($expectedCount = \count($expected), $violationsCount = \count($violations), \sprintf('%u violation(s) expected. Got %u.', $expectedCount, $violationsCount));
reset($violations);
foreach ($expected as $violation) {
Assert::assertEquals($violation, current($violations));
next($violations);
}
}
private function getViolation() : ConstraintViolation {
return new ConstraintViolation($this->message, $this->message, $this->parameters, $this->context
->getRoot(), $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause);
}
}