validator->validate([], new \Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude()); $this->assertNoViolation(); } public function testMixedUserGroupAndUsersIsValid(): void { $this->validator->validate( [new User(), new UserGroup()], new \Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude() ); $this->assertNoViolation(); } public function testDifferentExcludeKeysIsValid(): void { $this->validator->validate( [(new UserGroup())->setExcludeKey('A'), (new UserGroup())->setExcludeKey('B')], new \Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude() ); $this->assertNoViolation(); } public function testMultipleGroupsWithEmptyExcludeKeyIsValid(): void { $this->validator->validate( [(new UserGroup())->setExcludeKey(''), (new UserGroup())->setExcludeKey('')], new \Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude() ); $this->assertNoViolation(); } public function testSameExclusionKeyWillRaiseError(): void { $this->validator->validate( [ (new UserGroup())->setExcludeKey('A')->setLabel(['fr' => 'Group 1']), (new UserGroup())->setExcludeKey('A')->setLabel(['fr' => 'Group 2']), ], new \Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude() ); $this->buildViolation('The groups {{ excluded_groups }} do exclude themselves. Please choose one between them') ->setParameter('excluded_groups', 'Group 1, Group 2') ->setCode('e16c8226-0090-11ef-8560-f7239594db09') ->assertRaised(); } }