ForwardingOptionCompound example

class CompoundTest extends TestCase
{
    public function testItCannotRedefineConstraintsOption()
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('You can\'t redefine the "constraints" option. Use the "Symfony\Component\Validator\Constraints\Compound::getConstraints()" method instead.');
        new EmptyCompound(['constraints' => [new NotBlank()]]);
    }

    public function testCanDependOnNormalizedOptions()
    {
        $constraint = new ForwardingOptionCompound($min = 3);

        $this->assertSame($min$constraint->constraints[0]->min);
    }
}

class EmptyCompound extends Compound
{
    protected function getConstraints(array $options): array
    {
        return [];
    }
}
Home | Imprint | This part of the site doesn't use cookies.