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

Clone user pre send to actingas #121

Merged
merged 6 commits into from
May 20, 2024
Merged

Conversation

AZabolotnikov
Copy link

added method actingAs to trait AuthTestTrait, this solution solve problem when test user define as static in tests. This protect for change user object on batch testing.

Comment on lines 54 to 64
$mockedUser = new MockAuthUser();
$mockedUser->someIntProperty = 0;

$this->actingAs($mockedUser);

$user = Auth::user();
$user->someIntProperty = 1;

$this->actingAs($mockedUser);

$this->assertEquals(0, Auth::user()->someIntProperty);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to test it like this

Suggested change
$mockedUser = new MockAuthUser();
$mockedUser->someIntProperty = 0;
$this->actingAs($mockedUser);
$user = Auth::user();
$user->someIntProperty = 1;
$this->actingAs($mockedUser);
$this->assertEquals(0, Auth::user()->someIntProperty);
$mockedUser = new MockAuthUser();
$this->actingAs($mockedUser);
$this-> assertNotSame($mockedUser, Auth::user());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This work is great! Thanks.

tests/support/Mock/MockAuthUser.php Outdated Show resolved Hide resolved
@DenTray DenTray self-requested a review May 20, 2024 09:28
@DenTray DenTray merged commit 4fca293 into master May 20, 2024
2 checks passed
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.

None yet

3 participants