mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-13 06:51:29 +00:00
Test some more edge cases in tests
This commit is contained in:
parent
47ab18175f
commit
112e962239
8 changed files with 690 additions and 41 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue