Repository: symfony/symfony
File: src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php (PHP)

Code before:
        $this->expectException(UnexpectedTypeException::class);
        $this->expectExceptionMessage(sprintf('Expected argument of type "string", "%s" given', $type));

        $this->validator->validate([['value' => 5], ['id' => 1, 'value' => 6]], new Unique(fields: [$field]));
    }

    public static function getInvalidFieldNames(): array
    {
        return [
            ['stdClass', new \stdClass()],
            ['int', 2],
            ['bool', false],
        ];
    }

    /**
     * @dataProvider getValidCollectionValues
     */
    public function testValidCollectionValues(array $value, array $fields)
    {
        $this->validator->validate($value, new Unique(fields: $fields));

        $this->assertNoViolation();
    }

    public function getValidCollectionValues(): array
    {
        return [
            'unique empty item' => [
                [['field' => 1], ['field' => 2], []],
                ['field'],
            ],
            'unique non-array item' => [
                [['field' => 1], ['field' => 2], '', 1, null],
                ['field'],
            ],
        ];
    }

    /**
     * @dataProvider getInvalidCollectionValues
     */
    public function testInvalidCollectionValues(array $value, array $fields)
    {
        $this->validator->validate($value, new Unique([
            'message' => 'myMessage',
        ], fields: $fields));

        $this->buildViolation('myMessage')
            ->setParameter('{{ value }}', 'array')
            ->setCode(Unique::IS_NOT_UNIQUE)

Review comment (suggestion):
```suggestion
    public static function getValidCollectionValues(): array
```

Code after:
    {
        $this->expectException(UnexpectedTypeException::class);
        $this->expectExceptionMessage(\sprintf('Expected argument of type "string", "%s" given', $type));

        $this->validator->validate([['value' => 5], ['id' => 1, 'value' => 6]], new Unique(fields: [$field]));
    }

    public static function getInvalidFieldNames(): array
    {
        return [
            ['stdClass', new \stdClass()],
            ['int', 2],
            ['bool', false],
        ];
    }

    /**
     * @dataProvider getValidCollectionValues
     */
    public function testValidCollectionValues(array $value, array $fields)
    {
        $this->validator->validate($value, new Unique(fields: $fields));

        $this->assertNoViolation();
    }

    public static function getValidCollectionValues(): array
    {
        return [
            'unique empty item' => [
                [['field' => 1], ['field' => 2], []],
                ['field'],
            ],
            'unique non-array item' => [
                [['field' => 1], ['field' => 2], '', 1, null],
                ['field'],
            ],
        ];
    }

    /**
     * @dataProvider getInvalidCollectionValues
     */
    public function testInvalidCollectionValues(array $value, array $fields, string $expectedMessageParam)
    {
        $this->validator->validate($value, new Unique([
            'message' => 'myMessage',
        ], fields: $fields));

        $this->buildViolation('myMessage')
            ->setParameter('{{ value }}', $expectedMessageParam)