public function addGroup($group, $action, $priority = 0)
    {
        $this->assertNotFrozen();

        if (!empty($this->initialData[self::GROUPS][$action])) {
            foreach ($this->initialData[self::GROUPS][$action] as $existingGroup => $existingPriority) {
                if ($group !== $existingGroup && $priority === $existingPriority) {
                    throw new \InvalidArgumentException(
                        \sprintf(
                            'The priority %s cannot be used for the group "%s"'
                            . ' because the group with this priority already exists.'
                            . ' Existing group: "%s". Action: "%s".',
                            $priority,
                            $group,
                            $existingGroup,
                            $action
                        )
                    );
                }
            }
        }

        $this->initialData[self::GROUPS][$action][$group] = $priority;
    }