DummyConstraint example

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Tests\Fixtures\DummyConstraint;
use Symfony\Component\Validator\Tests\Fixtures\DummyConstraintValidator;

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()));
    }
}
use Symfony\Component\Validator\Constraints\Blank as BlankConstraint;
use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Tests\Fixtures\DummyConstraint;
use Symfony\Component\Validator\Tests\Fixtures\DummyConstraintValidator;

class ContainerConstraintValidatorFactoryTest extends TestCase
{
    public function testGetInstanceCreatesValidator()
    {
        $factory = new ContainerConstraintValidatorFactory(new Container());
        $this->assertInstanceOf(DummyConstraintValidator::class$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()
    {
Home | Imprint | This part of the site doesn't use cookies.