From 53bbc83504565e0c0c0c866f137f07fdc2a71c8e Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 5 Nov 2024 07:21:39 -0500 Subject: [PATCH] minor: unpack Foundry 2 proxies (#160) - un-deprecated unpacking Foundry 1 proxies --- src/Browser/KernelBrowser.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Browser/KernelBrowser.php b/src/Browser/KernelBrowser.php index 5ee509e..c715fda 100644 --- a/src/Browser/KernelBrowser.php +++ b/src/Browser/KernelBrowser.php @@ -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 @@ -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)); } @@ -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(); }