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

minor: unpack Foundry 2 proxies #160

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading