Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Remove redundant function call #12999

Closed
wants to merge 1 commit into from
Closed

[5.1] Remove redundant function call #12999

wants to merge 1 commit into from

Conversation

apollopy
Copy link
Contributor

@apollopy apollopy commented Apr 3, 2016

The login function will call updateSession function which will excute

$this->session->set($this->getName(), $id);

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Auth/Guard.php#L432

@apollopy apollopy changed the title Remove redundant function call [5.1]Remove redundant function call Apr 3, 2016
@apollopy apollopy changed the title [5.1]Remove redundant function call [5.1] Remove redundant function call Apr 3, 2016
@GrahamCampbell
Copy link
Member

What does this do please?

@apollopy
Copy link
Contributor Author

apollopy commented Apr 3, 2016

@GrahamCampbell
the explanation updated.

@taylorotwell
Copy link
Member

If it's not broken don't fix it. Had too many broken PRs lately.

@vlakoff
Copy link
Contributor

vlakoff commented Apr 4, 2016

This is a leftover from the first implementation which wasn't making any sense:

public function loginUsingId($id, $remember = false)
{
    $this->session->put($this->getName(), $id);

    return $this->login($this->user(), $remember);
}

Then it was fixed five months later in #1712, see how this retrieveById is welcome:

public function loginUsingId($id, $remember = false)
{
    $this->session->put($this->getName(), $id);

    return $this->login($this->provider->retrieveById($id), $remember);
}

(Then, it was again modified #2871 to return the user as stated in the phpdoc.)

So, it's not a redundant function call but rather a leftover from the first implementation which was entirely wrong.

@apollopy
Copy link
Contributor Author

apollopy commented Apr 4, 2016

The corresponding test cases are not understood

https://github.com/laravel/framework/blob/5.1/tests/Auth/AuthGuardTest.php#L245

the login function is return void, why test set will return user?

@vlakoff
Copy link
Contributor

vlakoff commented Apr 4, 2016

Just an overlook I suppose. The test wasn't impacted as the login return value is not used actually.

More importantly:

  • If no user is found for the given id, bad things happen. We should check retrieveById found an user before continuing, otherwise throw a proper error.
  • As login is mocked in the test, we aren't testing much. We should either:
    • test the whole thing, as in the tests above,
    • or simply test we are retrieving the expected user, logging with it, and returning it (basically what is done currently).

@vlakoff
Copy link
Contributor

vlakoff commented Apr 6, 2016

@taylorotwell What should be the behavior when Guard::loginUsingId (Laravel 5.1) or SessionGuard::loginUsingId (Laravel 5.2) is called with an invalid id? (throw exception, return false...) Current behavior: login is then called with null and errors happen.

@vlakoff
Copy link
Contributor

vlakoff commented Apr 12, 2016

Thoughts?

I'm ready to submit code for this, but I have to know what should be thrown if ever SessionGuard::loginUsingId were to be called with an invalid id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants