@Given there is a User with name :username in :parentGroup group

Ensures a user with username ':username' exists as a child of ':parentGroup' user group, can create either one.

@return \eZ\Publish\API\Repository\Values\User\User
196822
public function iHaveUserInGroup($username, $parentGroupName)
    {
        $email = $this->findNonExistingUserEmail($username);
        $password = $username;
        $user = $this->ensureUserExists($username, $email, $password, $parentGroupName);
    }
428272
private function findNonExistingUserName()
    {
        $userManager = $this->getUserManager();
        for ( $i = 0; $i < 20; $i++ )
        {
            $username = substr(uniqid('User#', true), 0, 15);
            if ( !$userManager->checkUserExistenceByUsername( $username ) )
            {
                return $username;
            }
        }

        throw new \Exception( 'Possible endless loop when attempting to find a new name for User.' );
    }
1128055
public function getUserNameElement()
    {
        $element = $this->getElement($this->usernameFieldName);

        if (! $element) {
            // Veld inlognaam
            $element = $this->createElement('text', $this->usernameFieldName);
            $element->setLabel($this->translate->_('Username'));
            $element->setAttrib('size', 40);
            $element->setRequired(true);

            $this->addElement($element);
        }

        return $element;
    }
1024112
public function getUsername()
    {
        if (!$this->hasEnabledUsername()) {
            return null;
        }
        $usernameClass = $this->usernameClass;
        $noInit = $usernameClass::buildNoInitModel();
        /* @var $noInit Username */
        return $this->hasOne($usernameClass, [$noInit->createdByAttribute => $this->guidAttribute]);
    }
912229
public function create()
    {
        /**
         * @var AdminUserInterface $adminUser
         */
        $classNamespace = $this->getEntityNamespace();
        $adminUser = new $classNamespace();
        $adminUser
            ->setGender(ElcodiUserProperties::GENDER_UNKNOWN)
            ->setToken($this->generator->generate(2))
            ->setEnabled(true)
            ->setCreatedAt($this->now());

        return $adminUser;
    }
1043022
protected function getUser()
    {
        if ($this->_user === null) {
            $user = \thienhungho\UserManagement\models\User::findByUsername($this->username);
            $this->_user = $user;
        }

        return $this->_user;
    }
1338047
private function get_user() {
        $userid = $this->backuprec->userid;
        $user = core_user::get_user($userid, '*', MUST_EXIST);

        return $user;
    }
724981
public function addUser(ChildUser $user)
    {
        if ($this->collUsers === null) {
            $this->initUsers();
        }

        if (!$this->getUsers()->contains($user)) {
            // only add it if the **same** object is not already associated
            $this->collUsers->push($user);
            $this->doAddUser($user);
        }

        return $this;
    }
551156
public function user()
    {
        if ($this->user !== null) {
            return $this->user;
        }

        if ($this->jwt->setRequest($this->request)->getToken() &&
            ($payload = $this->jwt->check(true)) &&
            $this->validateSubject()
        ) {
            return $this->user = $this->provider->retrieveById($payload['sub']);
        }
    }
1255004
protected function _getAuthor()
    {
        if ($this->created_by instanceof User) {
            return $this->created_by;
        }

        return new User([
            'username' => __d('content', 'unknown'),
            'name' => __d('content', 'Unknown'),
            'web' => __d('content', '(no website)'),
            'email' => __d('content', 'Unknown'),
        ]);
    }
478321
public function user()
    {
        if (!is_null($this->user)) {
            return $this->user;
        }
        $user = null;
        try {
            $resourceId = Authorizer::getResourceOwnerId();
            $resourceType = Authorizer::getResourceOwnerType();
        } catch (\Exception $e) {
            $resourceId = null;
            $resourceType = null;
            // throw $e;
        }
        if ($resourceType !== $this->id) {
            return null;
        }
        if (!empty($resourceId)) {
            $user = $this->getProvider()->retrieveById($resourceId);
        }
        return $this->user = $user;

    }
532179
public static function apacheUser ()
		{
			$possible = [ 'apache', 'www-data', '_www' ];
			foreach ($possible as $user)
			{
				if (posix_getpwnam($user) !== false)
					return $user;
			}

			$user = null;
			while (posix_getpwnam($user) === false)
				$user = readline("Enter apache username: ");

			return $user;
		}
987149
public function getParent()
    {
        return $this->owner
            ->hasOne($this->ownerClassName, [ $this->primaryKey => $this->parentIdField ])
            ->one();
    }
480894
public function createUsername($username)
    {
        if (!$this->hasEnabledUsername()) {
            return null;
        }
        $usernameClass = $this->usernameClass;
        $model = $usernameClass::findOne($this->getGUID());
        if (!$model) {
            $model = $this->create($usernameClass);
            $model->setGUID($this->getGUID());
        }
        $model->content = $username;
        return $model;
    }
143909
public function user()
    {
        if ($this->user !== null) {
            return $this->user;
        }

        if ($this->jwT->setRequest($this->request)->getToken() &&
            ($payload = $this->jwT->check(true)) &&
            $this->jwT->checkProvider($this->provider->getModel())
        ) {
            return $this->user = $this->provider->retrieveById($payload['sub']);
        }
    }
1238177
public function getUserNameElement()
    {
        $element = $this->getElement($this->usernameFieldName);

        if (! $element) {
            $element = parent::getUserNameElement();

            $element->addValidator(new \Gems_User_Validate_ResetRequestValidator($this, $this->translate));
        }

        return $element;
    }
885293
public function getParent()
    {
        if ($this->parent === null) {
            if (($parentId = $this->getParentPostId()) !== null) {
                $this->parent = $this->postFactory->create(get_post($parentId));
            } else {
                $this->parent = false;
            }
        }

        return $this->parent ?: null;
    }