src/Concerns/InteractsWithAuthSystem.php
public function actingAs($uid)
    {
        global $user;

        // Load the new requested user
        if (is_object($uid)) {
            if($uid->uid === 0) {
                $user = drupal_anonymous_user();
            } else{
                $user = user_load($uid->uid);
            }
        } else {
            if($uid === 0) {
                $user = drupal_anonymous_user();
            } else {
                $user = user_load($uid);
            }
        }

        $this->_cookies = [
            session_name() => session_id()
        ];

        return $this;
    }
public function actingAs($uid)
    {
        global $user;

        // Load the new requested user
        if (is_object($uid)) {
            if($uid->uid === 0) {
                $user = drupal_anonymous_user();
            } else{
                $user = user_load($uid->uid);
            }
        } else {
            if($uid === 0) {
                $user = drupal_anonymous_user();
            } else {
                $user = user_load($uid);
            }
        }

        $this->_cookies = [
            session_name() => session_id()
        ];

        return $this;
    }
Set the active user.

@param int|object $user Either a user object or simply a user id.
@return $this