ConstraintViolationBuilder example


  public function addViolation($message, array $parameters = []) {
    $this->violations->add(new ConstraintViolation($this->translator->trans($message$parameters$this->translationDomain)$message$parameters$this->root, $this->propertyPath, $this->value, NULL, NULL, $this->constraint));
  }

  /** * {@inheritdoc} */
  public function buildViolation($message, array $parameters = []): ConstraintViolationBuilderInterface {
    return new ConstraintViolationBuilder($this->violations, $this->constraint, $message$parameters$this->root, $this->propertyPath, $this->value, $this->translator, $this->translationDomain);
  }

  /** * {@inheritdoc} */
  public function getViolations(): ConstraintViolationListInterface {
    return $this->violations;
  }

  /** * {@inheritdoc} */
private ConstraintViolationBuilder $builder;

    protected function setUp(): void
    {
        $this->root = [
            'data' => [
                'foo' => 'bar',
                'baz' => 'foobar',
            ],
        ];
        $this->violations = new ConstraintViolationList();
        $this->builder = new ConstraintViolationBuilder($this->violations, new Valid()$this->messageTemplate, []$this->root, 'data', 'foo', new IdentityTranslator());
    }

    public function testAddViolation()
    {
        $this->builder->addViolation();

        $this->assertViolationEquals(new ConstraintViolation($this->messageTemplate, $this->messageTemplate, []$this->root, 'data', 'foo', null, null, new Valid()));
    }

    public function testAppendPropertyPath()
    {
        
$this->root,
            $this->propertyPath,
            $this->getValue(),
            null,
            null,
            $this->constraint
        ));
    }

    public function buildViolation(string $message, array $parameters = []): ConstraintViolationBuilderInterface
    {
        return new ConstraintViolationBuilder(
            $this->violations,
            $this->constraint,
            $message,
            $parameters,
            $this->root,
            $this->propertyPath,
            $this->getValue(),
            $this->translator,
            $this->translationDomain
        );
    }

    
$this->root,
            $this->propertyPath,
            $this->getValue(),
            null,
            null,
            $this->constraint
        ));
    }

    public function buildViolation(string $message, array $parameters = []): ConstraintViolationBuilderInterface
    {
        return new ConstraintViolationBuilder(
            $this->violations,
            $this->constraint,
            $message,
            $parameters,
            $this->root,
            $this->propertyPath,
            $this->getValue(),
            $this->translator,
            $this->translationDomain
        );
    }

    
Home | Imprint | This part of the site doesn't use cookies.