expectFailingValueValidation example

$this->assertNoViolation();
    }

    public function testConstraintViolations()
    {
        $constraints = [
            new Blank([
                'message' => 'my_message',
            ]),
        ];
        $this->expectFailingValueValidation(
            0,
            'foo',
            $constraints,
            null,
            new ConstraintViolation(
                'my_message',
                'my_message',
                [
                    '{{ value }}' => 'foo',
                ],
                null,
                
public function testStopsAtFirstConstraintWithViolations()
    {
        $constraints = [
            new Type('string'),
            new Regex(['pattern' => '[a-z]']),
            new NotEqualTo('Foo'),
        ];

        $value = 'Foo';

        $this->expectValidateValue(0, $value[$constraints[0]]);
        $this->expectFailingValueValidation(1, $value[$constraints[1]], null, new ConstraintViolation('regex error', null, [], null, '', null, null, 'regex'));

        $this->validator->validate($valuenew Sequentially($constraints));

        $this->assertCount(1, $this->context->getViolations());
    }

    public function testNestedConstraintsAreNotExecutedWhenGroupDoesNotMatch()
    {
        $validator = Validation::createValidator();

        $violations = $validator->validate(50, new Sequentially([
            
$constraints = [new Range(['min' => 2, 'max' => 5])];

        $constraint = new Expression(
            ['expression' => 'is_valid(this.data, a)', 'values' => ['a' => $constraints]]
        );

        $object = new Entity();
        $object->data = 7;

        $this->setObject($object);

        $this->expectFailingValueValidation(
            0,
            7,
            $constraints,
            null,
            new ConstraintViolation('error_range', '', [], '', '', 7, null, 'range')
        );

        $this->validator->validate($object$constraint);

        $this->assertCount(2, $this->context->getViolations());
    }

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