Skip to content

Commit

Permalink
clone so user doesnt get attached to the facade singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Jan 5, 2024
1 parent caf98e1 commit 5f9acb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/Git/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ public function statuses()
return $statuses->isNotEmpty() ? $statuses : null;
}

public function as($user)
/**
* Act as a specific user.
*/
public function as(?UserContract $user): static
{
$this->authenticatedUser = $user;
$clone = clone $this;

$clone->authenticatedUser = $user;

return $this;
return $clone;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Git/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ public function it_gets_git_user_info()
->data(['name' => 'Han Solo'])
->makeSuper();

Git::as($han);

$this->assertEquals('Han Solo', Git::gitUserName());
$this->assertEquals('han@solo.com', Git::gitUserEmail());
$this->assertEquals('Han Solo', Git::as($han)->gitUserName());
$this->assertEquals('[email protected]', Git::as($han)->gitUserEmail());
$this->assertEquals('Chewy', Git::gitUserName());
$this->assertEquals('chew@bacca.com', Git::gitUserEmail());

Config::set('statamic.git.use_authenticated', false);

Expand Down

0 comments on commit 5f9acb4

Please sign in to comment.