Skip to content

Commit

Permalink
minor: unpack Foundry 2 proxies (#160)
Browse files Browse the repository at this point in the history
- un-deprecated unpacking Foundry 1 proxies
  • Loading branch information
kbond authored Nov 5, 2024
1 parent 9603f3d commit 53bbc83
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Browser/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use Zenstruck\Browser\Session\Driver\BrowserKitDriver;
use Zenstruck\Callback\Parameter;
use Zenstruck\Foundry\Factory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Proxy As LegacyProxy;

/**
* @author Kevin Bond <[email protected]>
Expand Down Expand Up @@ -138,11 +139,14 @@ public function actingAs(object $user, ?string $firewall = null): self
$user = $user->create(); // @phpstan-ignore-line
}

if ($user instanceof Proxy) { // @phpstan-ignore-line
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Proxy to actingAs() is deprecated, pass the real object instead.');
if ($user instanceof LegacyProxy) { // @phpstan-ignore-line
$user = $user->object(); // @phpstan-ignore-line
}

if ($user instanceof Proxy) { // @phpstan-ignore-line
$user = $user->_real(); // @phpstan-ignore-line
}

if (!$user instanceof UserInterface) {
throw new \LogicException(\sprintf('%s() requires the user be an instance of %s.', __METHOD__, UserInterface::class));
}
Expand Down Expand Up @@ -178,11 +182,14 @@ public function assertAuthenticated($as = null): self
$as = $as->create(); // @phpstan-ignore-line
}

if ($as instanceof Proxy) { // @phpstan-ignore-line
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Proxy to assertAuthenticated() is deprecated, pass the real object instead.');
if ($as instanceof LegacyProxy) { // @phpstan-ignore-line
$as = $as->object(); // @phpstan-ignore-line
}

if ($as instanceof Proxy) { // @phpstan-ignore-line
$as = $as->_real(); // @phpstan-ignore-line
}

if ($as instanceof UserInterface) {
$as = $as->getUserIdentifier();
}
Expand Down

0 comments on commit 53bbc83

Please sign in to comment.