Test some more edge cases in tests

This commit is contained in:
Jan Böhmer 2026-05-11 23:13:46 +02:00
parent 47ab18175f
commit 112e962239
8 changed files with 690 additions and 41 deletions

View file

@ -154,6 +154,33 @@ final class UniqueObjectCollectionValidatorTest extends ConstraintValidatorTestC
->assertRaised();
}
public function testThirdElementDuplicatePointsToIndexTwo(): void
{
// First two elements are unique; only the third duplicates the first.
$this->validator->validate(new ArrayCollection([
new DummyUniqueValidatableObject(['a' => 1]),
new DummyUniqueValidatableObject(['a' => 2]),
new DummyUniqueValidatableObject(['a' => 1]), // duplicate of index 0
]),
new UniqueObjectCollection(fields: ['a']));
$this
->buildViolation('This value is already used.')
->setCode(UniqueObjectCollection::IS_NOT_UNIQUE)
->setParameter('{{ object }}', 'objectString')
->atPath('property.path[2].a')
->assertRaised();
}
public function testAllNullsWithAllowNullProducesNoViolation(): void
{
$this->validator->validate(new ArrayCollection([
new DummyUniqueValidatableObject(['a' => null]),
new DummyUniqueValidatableObject(['a' => null]),
new DummyUniqueValidatableObject(['a' => null]),
]),
new UniqueObjectCollection(fields: ['a'], allowNull: true));
$this->assertNoViolation();
}
}