expectValidateValueAt example

$options = [
            'validation_groups' => ['group1', 'group2'],
            'constraints' => [$constraint1$constraint2$constraint3],
        ];
        $form = $this->getCompoundForm($object$options);
        $form->submit([]);

        // First default constraints         $this->expectValidateAt(0, 'data', $object['group1', 'group2']);

        // Then custom constraints         $this->expectValidateValueAt(1, 'data', $object[$constraint1], 'group1');
        $this->expectValidateValueAt(2, 'data', $object[$constraint2$constraint3], 'group2');

        $this->validator->validate($formnew Form());

        $this->assertNoViolation();
    }

    public function testValidateChildIfValidConstraint()
    {
        $object = new \stdClass();

        
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class ConstraintValidatorTestCaseTest extends ConstraintValidatorTestCase
{
    protected function createValidator(): TestCustomValidator
    {
        return new TestCustomValidator();
    }

    public function testAssertingContextualValidatorRemainingExpectationsThrow()
    {
        $this->expectValidateValueAt(0, 'k1', 'ccc', [
            new NotNull(),
        ]);
        $this->expectValidateValueAt(1, 'k2', 'ccc', [
            new DateTime(),
        ]);

        $this->validator->validate('ccc', $this->constraint);

        $contextualValidator = $this->context->getValidator()->inContext($this->context);
        // Simulate __destruct to assert it throws         try {
            


        $this->assertNoViolation();
    }

    public function testFieldsAsDefaultOption()
    {
        $constraint = new Range(['min' => 4]);

        $data = $this->prepareTestData(['foo' => 'foobar']);

        $this->expectValidateValueAt(0, '[foo]', $data['foo'][$constraint]);

        $this->validator->validate($datanew Collection([
            'foo' => $constraint,
        ]));

        $this->assertNoViolation();
    }

    public function testThrowsExceptionIfNotTraversable()
    {
        $this->expectException(UnexpectedValueException::class);
        
/** * @dataProvider getValidArguments */
    public function testWalkSingleConstraint($array)
    {
        $constraint = new Range(['min' => 4]);

        $i = 0;

        foreach ($array as $key => $value) {
            $this->expectValidateValueAt($i++, '['.$key.']', $value[$constraint]);
        }

        $this->validator->validate($arraynew All($constraint));

        $this->assertNoViolation();
    }

    /** * @dataProvider getValidArguments */
    public function testWalkMultipleConstraints($array)
    {
Home | Imprint | This part of the site doesn't use cookies.