Skip to content

Commit

Permalink
feat: clone user object pre send to actingAs
Browse files Browse the repository at this point in the history
  • Loading branch information
t0xas committed May 17, 2024
1 parent 9d912f4 commit 54ca273
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/AuthTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace RonasIT\Support\Tests;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use RonasIT\Support\Tests\Support\Mock\MockAuthUser;
use RonasIT\Support\Traits\AuthTestTrait;
use RonasIT\Support\Traits\FixturesTrait;

Expand Down Expand Up @@ -46,4 +48,19 @@ public function testActingWithEmptySession()

$this->assertEmpty($loginSession);
}

public function testActingAs()
{
$mockedUser = new MockAuthUser();
$mockedUser->someIntProperty = 0;

$this->actingAs($mockedUser);

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

$this->actingAs($mockedUser);

$this->assertEquals(0, Auth::user()->someIntProperty);
}
}
39 changes: 39 additions & 0 deletions tests/support/Mock/MockAuthUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RonasIT\Support\Tests\Support\Mock;

use Illuminate\Contracts\Auth\Authenticatable;

class MockAuthUser implements Authenticatable
{
public int $someIntProperty;

public function getAuthIdentifierName()
{
return 'some_auth_identifier_name';
}

public function getAuthIdentifier()
{
return 'some_auth_identifier';
}

public function getAuthPassword()
{
return 'some_auth_password';
}

public function getRememberToken()
{
return 'some_remember_token';
}

public function setRememberToken($value)
{
}

public function getRememberTokenName()
{
return 'some_remember_token_name';
}
}

0 comments on commit 54ca273

Please sign in to comment.