DummyConstraintValidator example

class ConstraintValidatorFactoryTest extends TestCase
{
    public function testGetInstance()
    {
        $factory = new ConstraintValidatorFactory();
        $this->assertInstanceOf(DummyConstraintValidator::class$factory->getInstance(new DummyConstraint()));
    }

    public function testPredefinedGetInstance()
    {
        $validator = new DummyConstraintValidator();
        $factory = new ConstraintValidatorFactory([DummyConstraintValidator::class => $validator]);
        $this->assertSame($validator$factory->getInstance(new DummyConstraint()));
    }
}
public function testGetInstanceReturnsExistingValidator()
    {
        $factory = new ContainerConstraintValidatorFactory(new Container());
        $v1 = $factory->getInstance(new BlankConstraint());
        $v2 = $factory->getInstance(new BlankConstraint());
        $this->assertSame($v1$v2);
    }

    public function testGetInstanceReturnsService()
    {
        $validator = new DummyConstraintValidator();
        $container = new Container();
        $container->set(DummyConstraintValidator::class$validator);

        $factory = new ContainerConstraintValidatorFactory($container);

        $this->assertSame($validator$factory->getInstance(new DummyConstraint()));
    }

    public function testGetInstanceInvalidValidatorClass()
    {
        $this->expectException(ValidatorException::class);
        
Home | Imprint | This part of the site doesn't use cookies.