-
Notifications
You must be signed in to change notification settings - Fork 11k
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.7] Fix actingAs #25873
[5.7] Fix actingAs #25873
Conversation
@laurencei might be worth to send this to master for 5.8 because I think this will probably be a breaking change for some people. |
Whilst I dont disagree it might break - it would only break test cases, which are actually returning incorrect results though? i.e. this is a bug fix of an incorrect value. If I had a test that I wanted explicitly to get a Production returns would be unchanged obviously. I'll leave it and if Taylor says I can change it - happy either way. |
@laurencei fair enough :) |
Wish the commit would contain the great PR description 😂 |
@@ -29,6 +29,10 @@ public function actingAs(UserContract $user, $driver = null) | |||
*/ | |||
public function be(UserContract $user, $driver = null) | |||
{ | |||
if (isset($user->wasRecentlyCreated) && $user->wasRecentlyCreated) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as this?
if ($user->wasRecentlyCreated ?? false) { }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably... 😄
This happens across the board with testing for any model. Doesn't make sense to just patch this one case. It would've been best to just let the developer account for this, or revert the magic that causes it. |
@devcircus - No it doesnt. It only occurs for an auth user - because you directly pass the newly created model into the Any other models created prior to the request are retrieved during the request, and therefore are not That's why this was a specific target. |
This fixes #25868 (and duplicates #21107, #25775 and #23270)
So fresh install of Laravel 5.7:
This test fails - because
Response status code [201] does not match expected 200 status code.
This is a bug.
The
$user
was created before the start of the reqeust. i.e. we did not create a new user and return it inside of/test
. The creation of$user
is just to setup the requirements of the test.The point of
201
is the request was successful and you created a resource. But in the test above - I did not create a resource inside of that request.This PR ensures that anyone pre-authenticated (using
actingAs()
orbe()
) is never marked as newly created - since that is logically impossible (you cant be pre-authenticated against a resource that doesnt exist before the request even begins).In other words - you must already have a preexisting user to
be/act
as them