Unique example


            ['FOO', [
                new Choice(['choices' => ['bar', 'BAR']]),
                new Regex(['pattern' => '/foo/i']),
            ]],
            ['fr', [
                new Country(),
                new Language(),
            ]],
            [[1, 3, 5][
                new Count(['min' => 5]),
                new Unique(),
            ]],
        ];
    }

    /** * @dataProvider getInvalidCombinations */
    public function testInvalidCombinationsWithDefaultMessage($value$constraints)
    {
        $atLeastOneOf = new AtLeastOneOf(['constraints' => $constraints]);
        $validator = Validation::createValidator();

        
class UniqueValidatorTest extends ConstraintValidatorTestCase
{
    protected function createValidator(): UniqueValidator
    {
        return new UniqueValidator();
    }

    public function testExpectsUniqueConstraintCompatibleType()
    {
        $this->expectException(UnexpectedValueException::class);
        $this->validator->validate('', new Unique());
    }

    /** * @dataProvider getValidValues */
    public function testValidValues($value)
    {
        $this->validator->validate($valuenew Unique());

        $this->assertNoViolation();
    }

    
self::assertSame(['my_group']$cConstraint->groups);
        self::assertSame('some attached data', $cConstraint->payload);

        [$dConstraint] = $metadata->properties['d']->getConstraints();
        self::assertSame('intval', $dConstraint->normalizer);
    }

    public function testInvalidNormalizerThrowsException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "normalizer" option must be a valid callable ("string" given).');
        new Unique(['normalizer' => 'Unknown Callable']);
    }

    public function testInvalidNormalizerObjectThrowsException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "normalizer" option must be a valid callable ("stdClass" given).');
        new Unique(['normalizer' => new \stdClass()]);
    }
}

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