setUserIdentifier($username); $user->setEmail($email); if (!empty($roles)) { $user->setRoles($roles); $defaultFields[] = 'roles'; } $this->assertHasViolationForField($user, $defaultFields, ['Profile']); } public function testInvalidRoles(): void { $user = new User(); $user->setUserIdentifier('foo'); $user->setEmail('foo@example.com'); $user->setRoles(['xxxxxx']); $this->assertHasViolationForField($user, ['roles'], ['RolesUpdate']); } public function testValidRoles(): void { $user = new User(); $user->setUserIdentifier('foo'); $user->setEmail('foo@example.com'); $user->setRoles(['ROLE_TEAMLEAD']); $this->assertHasNoViolations($user, ['RolesUpdate']); } public static function getValidTestData() { return [ [str_pad('#', 8, '-'), 'test@x.x'], // shortest possible username [str_pad('#', 64, '-'), 'test@x.x'], // longest possible username ]; } /** * @dataProvider getValidTestData */ public function testValidValues($username, $email, $roles = []): void { $user = new User(); $user->setUserIdentifier($username); $user->setEmail($email); if (!empty($roles)) { $user->setRoles($roles); } $this->assertHasNoViolations($user, ['Profile']); } }