From 33f2a0f08cb21fa1b21cf7a16229fac9fb27fe81 Mon Sep 17 00:00:00 2001 From: kbond Date: Mon, 1 Apr 2024 01:11:25 +0000 Subject: [PATCH 01/10] bot: fix cs [skip ci] --- tests/NormalizationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/NormalizationTest.php b/tests/NormalizationTest.php index 863a882..ffd4e19 100644 --- a/tests/NormalizationTest.php +++ b/tests/NormalizationTest.php @@ -89,8 +89,8 @@ public static function edgeCaseTestNames(): \Generator ]; yield 'escaped simple quote' => [ 'test name' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"', - 'expected output' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0', - ]; + 'expected output' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0', + ]; yield 'single quote for array index access' => [ 'test name' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"', 'expected output' => $baseTemplate.'te-id-filter-system-st__0', From 3dd63db6d24aab7ead87d00f5a4f975b050a729e Mon Sep 17 00:00:00 2001 From: kbond Date: Fri, 16 Aug 2024 01:16:43 +0000 Subject: [PATCH 02/10] bot: fix cs [skip ci] --- tests/HttpOptionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/HttpOptionsTest.php b/tests/HttpOptionsTest.php index bccc5c9..bf9a0ab 100644 --- a/tests/HttpOptionsTest.php +++ b/tests/HttpOptionsTest.php @@ -196,7 +196,7 @@ public function json_ajax_constructor_with_no_value(): void */ public function create_with_self(): void { - $options = new class() extends HttpOptions {}; + $options = new class extends HttpOptions {}; $this->assertSame($options, HttpOptions::create($options)); } From d90bad93782be1f75f498d0f76b3c1a3b0229e98 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 8 Oct 2024 20:40:47 -0400 Subject: [PATCH 03/10] minor: sca --- src/Browser/Test/LegacyExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Browser/Test/LegacyExtension.php b/src/Browser/Test/LegacyExtension.php index 94f1d26..7842c27 100644 --- a/src/Browser/Test/LegacyExtension.php +++ b/src/Browser/Test/LegacyExtension.php @@ -122,7 +122,7 @@ private static function normalizeTestName(string $name): string \preg_match('#^(?[\w:\\\]+) with data set "(?.*)"#', $name, $matches); } - $normalized = \strtr($matches['test'], '\\:', '-_'); + $normalized = \strtr($matches['test'], '\\:', '-_'); // @phpstan-ignore-line if (isset($matches['dataset'])) { $normalized .= '__data-set-'.\preg_replace('/\W+/', '-', $matches['dataset']); From 3b4d4a49dc636b9ec6afd7572c088d041f2a1f3a Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 8 Oct 2024 20:57:04 -0400 Subject: [PATCH 04/10] minor: fix tests --- tests/NormalizationTest.php | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/NormalizationTest.php b/tests/NormalizationTest.php index ffd4e19..5a97619 100644 --- a/tests/NormalizationTest.php +++ b/tests/NormalizationTest.php @@ -42,8 +42,8 @@ public static function namesProvider(): \Generator $baseTemplate = 'error_'.__METHOD__; yield 'test name without datasets' => [ - 'test name' => __METHOD__, - 'expected output' => \strtr($baseTemplate, '\\:', '-_').'__0', + 'testName' => __METHOD__, + 'expectedOutput' => \strtr($baseTemplate, '\\:', '-_').'__0', ]; $datasetTemplate = $baseTemplate.'__data-set-%s__0'; @@ -55,20 +55,20 @@ public static function namesProvider(): \Generator $numericOutput = \strtr($numericTemplate, '\\:', '-_'); yield 'phpunit 10 alpha' => [ - 'test name' => __METHOD__.' with data set "test set"', - 'expected output' => $alphaOutput, + 'testName' => __METHOD__.' with data set "test set"', + 'expectedOutput' => $alphaOutput, ]; yield 'phpunit 10 numeric' => [ - 'test name' => __METHOD__.' with data set #0', - 'expected output' => $numericOutput, + 'testName' => __METHOD__.' with data set #0', + 'expectedOutput' => $numericOutput, ]; yield 'legacy alpha' => [ - 'test name' => __METHOD__.' with data set "test set" (test set)', - 'expected output' => $alphaOutput, + 'testName' => __METHOD__.' with data set "test set" (test set)', + 'expectedOutput' => $alphaOutput, ]; yield 'legacy numeric' => [ - 'test name' => __METHOD__.' with data set #0 (test set)', - 'expected output' => $numericOutput, + 'testName' => __METHOD__.' with data set #0 (test set)', + 'expectedOutput' => $numericOutput, ]; } @@ -76,28 +76,28 @@ public static function edgeCaseTestNames(): \Generator { $baseTemplate = \strtr('error_'.__METHOD__.'__data-set-', '\\:', '-_'); yield 'self within moustache' => [ - 'test name' => __METHOD__.' with data set "te{{self}}st" (test set)', - 'expected output' => $baseTemplate.'te-self-st__0', + 'testName' => __METHOD__.' with data set "te{{self}}st" (test set)', + 'expectedOutput' => $baseTemplate.'te-self-st__0', ]; yield 'double quoted with space' => [ - 'test name' => __METHOD__.' with data set "_self.env.setCache("uri://host.net:2121") _self.env.loadTemplate("other-host")" (test set)', - 'expected output' => $baseTemplate.'_self-env-setCache-uri-host-net-2121-_self-env-loadTemplate-other-host-__0', + 'testName' => __METHOD__.' with data set "_self.env.setCache("uri://host.net:2121") _self.env.loadTemplate("other-host")" (test set)', + 'expectedOutput' => $baseTemplate.'_self-env-setCache-uri-host-net-2121-_self-env-loadTemplate-other-host-__0', ]; yield 'double quotes in moustache' => [ - 'test name' => __METHOD__.' with data set "te{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}st"', - 'expected output' => $baseTemplate.'te-_self-env-registerUndefinedFilterCallback-exec-_self-env-getFilter-id-st__0', + 'testName' => __METHOD__.' with data set "te{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}st"', + 'expectedOutput' => $baseTemplate.'te-_self-env-registerUndefinedFilterCallback-exec-_self-env-getFilter-id-st__0', ]; yield 'escaped simple quote' => [ - 'test name' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"', - 'expected output' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0', + 'testName' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"', + 'expectedOutput' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0', ]; yield 'single quote for array index access' => [ - 'test name' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"', - 'expected output' => $baseTemplate.'te-id-filter-system-st__0', + 'testName' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"', + 'expectedOutput' => $baseTemplate.'te-id-filter-system-st__0', ]; yield 'numeric array access' => [ - 'test name' => __METHOD__.' with data set "te{{[0]|reduce(\'system\',\'id\')}}st"', - 'expected output' => $baseTemplate.'te-0-reduce-system-id-st__0', + 'testName' => __METHOD__.' with data set "te{{[0]|reduce(\'system\',\'id\')}}st"', + 'expectedOutput' => $baseTemplate.'te-0-reduce-system-id-st__0', ]; } } From d3a52e9882f9794e77bff632a053a96eb7461314 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 8 Oct 2024 21:31:24 -0400 Subject: [PATCH 05/10] feat: deprecate foundry integration --- README.md | 6 +--- composer.json | 7 ++-- src/Browser/KernelBrowser.php | 24 ++++++++------ tests/Fixture/Kernel.php | 5 --- tests/KernelBrowserAuthenticationTest.php | 39 +---------------------- 5 files changed, 19 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 9bc9a0d..f79f6fc 100644 --- a/README.md +++ b/README.md @@ -320,9 +320,6 @@ $browser // authenticate a user for subsequent actions ->actingAs($user) // \Symfony\Component\Security\Core\User\UserInterface - // If using zenstruck/foundry, you can pass a factory/proxy - ->actingAs(UserFactory::new()) - // fail if authenticated ->assertNotAuthenticated() @@ -332,8 +329,7 @@ $browser // fails if NOT authenticated as "kbond" ->assertAuthenticated('kbond') - // \Symfony\Component\Security\Core\User\UserInterface or, if using - // zenstruck/foundry, you can pass a factory/proxy + // \Symfony\Component\Security\Core\User\UserInterface ->assertAuthenticated($user) ; ``` diff --git a/composer.json b/composer.json index 1abf15f..d14913f 100644 --- a/composer.json +++ b/composer.json @@ -23,15 +23,14 @@ }, "require-dev": { "dbrekelmans/bdi": "^1.0", - "justinrainbow/json-schema": "^5.2", + "justinrainbow/json-schema": "^5.3", "mtdowling/jmespath.php": "^2.6", "phpstan/phpstan": "^1.4", - "phpunit/phpunit": "^9.5|^10.4", + "phpunit/phpunit": "^9.6.21|^10.4", "symfony/mime": "^5.4|^6.0|^7.0", "symfony/panther": "^1.1|^2.0.1", "symfony/phpunit-bridge": "^6.0|^7.0", - "symfony/security-bundle": "^5.4|^6.0|^7.0", - "zenstruck/foundry": "^1.30" + "symfony/security-bundle": "^5.4|^6.0|^7.0" }, "suggest": { "justinrainbow/json-schema": "Json schema validator. Needed to use Json::assertMatchesSchema().", diff --git a/src/Browser/KernelBrowser.php b/src/Browser/KernelBrowser.php index e3bf49e..5ee509e 100644 --- a/src/Browser/KernelBrowser.php +++ b/src/Browser/KernelBrowser.php @@ -127,18 +127,20 @@ final public function withProfiling(): self } /** - * @param UserInterface|Proxy|Factory $user + * @param UserInterface $user * * @return static */ public function actingAs(object $user, ?string $firewall = null): self { - if ($user instanceof Factory) { - $user = $user->create(); + if ($user instanceof Factory) { // @phpstan-ignore-line + trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to actingAs() is deprecated, pass the created object instead.'); + $user = $user->create(); // @phpstan-ignore-line } - if ($user instanceof Proxy) { - $user = $user->object(); + 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.'); + $user = $user->object(); // @phpstan-ignore-line } if (!$user instanceof UserInterface) { @@ -151,7 +153,7 @@ public function actingAs(object $user, ?string $firewall = null): self } /** - * @param string|UserInterface|Proxy|Factory|null $as + * @param string|UserInterface|null $as * * @return static */ @@ -171,12 +173,14 @@ public function assertAuthenticated($as = null): self return $this; } - if ($as instanceof Factory) { - $as = $as->create(); + if ($as instanceof Factory) { // @phpstan-ignore-line + trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to assertAuthenticated() is deprecated, pass the created object instead.'); + $as = $as->create(); // @phpstan-ignore-line } - if ($as instanceof Proxy) { - $as = $as->object(); + 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.'); + $as = $as->object(); // @phpstan-ignore-line } if ($as instanceof UserInterface) { diff --git a/tests/Fixture/Kernel.php b/tests/Fixture/Kernel.php index b501937..90b2044 100644 --- a/tests/Fixture/Kernel.php +++ b/tests/Fixture/Kernel.php @@ -28,7 +28,6 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; use Symfony\Component\Security\Core\User\InMemoryUser; -use Zenstruck\Foundry\ZenstruckFoundryBundle; /** * @author Kevin Bond @@ -173,7 +172,6 @@ public function registerBundles(): iterable { yield new FrameworkBundle(); yield new SecurityBundle(); - yield new ZenstruckFoundryBundle(); } protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void @@ -209,9 +207,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load } $c->loadFromExtension('security', $security); - $c->loadFromExtension('zenstruck_foundry', [ - 'auto_refresh_proxies' => false, - ]); $c->register('logger', NullLogger::class); // disable logging } diff --git a/tests/KernelBrowserAuthenticationTest.php b/tests/KernelBrowserAuthenticationTest.php index 2ecaa36..96323ea 100644 --- a/tests/KernelBrowserAuthenticationTest.php +++ b/tests/KernelBrowserAuthenticationTest.php @@ -17,16 +17,13 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\User\InMemoryUser; use Zenstruck\Browser\Test\HasBrowser; -use Zenstruck\Foundry\Test\Factories; - -use function Zenstruck\Foundry\anonymous; /** * @author Kevin Bond */ final class KernelBrowserAuthenticationTest extends KernelTestCase { - use Factories, HasBrowser; + use HasBrowser; /** * @test @@ -41,36 +38,6 @@ public function can_act_as_user(): void ; } - /** - * @test - */ - public function can_act_as_user_with_foundry_factory(): void - { - $user = anonymous(InMemoryUser::class, ['username' => 'kevin', 'password' => 'pass']); - - $this->browser() - ->throwExceptions() - ->actingAs($user) - ->visit('/user') - ->assertSee('user: kevin/pass') - ; - } - - /** - * @test - */ - public function can_act_as_user_with_foundry_proxy(): void - { - $user = anonymous(InMemoryUser::class)->create(['username' => 'kevin', 'password' => 'pass']); - - $this->browser() - ->throwExceptions() - ->actingAs($user) - ->visit('/user') - ->assertSee('user: kevin/pass') - ; - } - /** * @test */ @@ -78,8 +45,6 @@ public function can_make_authentication_assertions(): void { $username = 'kevin'; $user = new InMemoryUser('kevin', 'pass'); - $factory = anonymous(InMemoryUser::class, ['username' => 'kevin', 'password' => 'pass']); - $proxy = anonymous(InMemoryUser::class)->create(['username' => 'kevin', 'password' => 'pass']); $this->browser() ->assertNotAuthenticated() @@ -87,8 +52,6 @@ public function can_make_authentication_assertions(): void ->assertAuthenticated() ->assertAuthenticated($username) ->assertAuthenticated($user) - ->assertAuthenticated($factory) - ->assertAuthenticated($proxy) ->visit('/user') ->assertAuthenticated() ->assertAuthenticated($username) From 6175462e0286b88360478bcdb7787443b39ae0df Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sun, 20 Oct 2024 19:02:23 -0400 Subject: [PATCH 06/10] feat: add `BROWSER_ALWAYS_START_WEBSERVER` env var (#156) --- README.md | 44 ++++++++++++++++++++------------- src/Browser/Test/HasBrowser.php | 5 ++++ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f79f6fc..d8484d1 100644 --- a/README.md +++ b/README.md @@ -407,7 +407,7 @@ $browser Make assertions about json responses using [JMESPath expressions](https://jmespath.org/) See the [JMESPath Tutorials](https://jmespath.org/tutorial.html) to learn more. -> **Note** +> [!NOTE] > `mtdowling/jmespath.php` is required: `composer require --dev mtdowling/jmespath.php`. ```php @@ -453,13 +453,21 @@ $json = $browser ; ``` -> **Note** +> [!NOTE] > See the [full `zenstruck/assert` expectation API documentation](https://github.com/zenstruck/assert#expectation-api) > to see all the methods available on `Zenstruck\Browser\Json`. ### PantherBrowser -*The `PantherBrowser` is experimental in 1.0 and may be subject to BC Breaks.* +> [!NOTE] +> The `PantherBrowser` is experimental in 1.0 and may be subject to BC Breaks. + +> [!TIP] +> By default, Panther will not start a web server if it detects one already running +> with the Symfony CLI. This is likely running in your `dev` environment and will cause +> unexpected test failures. Set the env variable `BROWSER_ALWAYS_START_WEBSERVER=1` +> to always start a webserver configured for your current test env when running +> Panther tests. This browser has the following extra methods: @@ -543,17 +551,18 @@ class MyTest extends PantherTestCase There are several environment variables available to configure: -| Variable | Description | Default | -|----------------------------|--------------------------------------------------------------------------------------------|------------------------------------| -| `BROWSER_SOURCE_DIR` | Directory to save source files to. | `./var/browser/source` | -| `BROWSER_SCREENSHOT_DIR` | Directory to save screenshots to (only applies to `PantherBrowser`). | `./var/browser/screenshots` | -| `BROWSER_CONSOLE_LOG_DIR` | Directory to save javascript console logs to (only applies to `PantherBrowser`). | `./var/browser/console-logs` | -| `BROWSER_FOLLOW_REDIRECTS` | Whether to follow redirects by default (only applies to `KernelBrowser`). | `1` _(true)_ | -| `BROWSER_CATCH_EXCEPTIONS` | Whether to catch exceptions by default (only applies to `KernelBrowser`). | `1` _(true)_ | -| `BROWSER_SOURCE_DEBUG` | Whether to add request metadata to written source files (only applies to `KernelBrowser`). | `0` _(false)_ | -| `KERNEL_BROWSER_CLASS` | `KernelBrowser` class to use. | `Zenstruck\Browser\KernelBrowser` | -| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` | -| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ | +| Variable | Description | Default | +|----------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------| +| `BROWSER_SOURCE_DIR` | Directory to save source files to. | `./var/browser/source` | +| `BROWSER_SCREENSHOT_DIR` | Directory to save screenshots to (only applies to `PantherBrowser`). | `./var/browser/screenshots` | +| `BROWSER_CONSOLE_LOG_DIR` | Directory to save javascript console logs to (only applies to `PantherBrowser`). | `./var/browser/console-logs` | +| `BROWSER_FOLLOW_REDIRECTS` | Whether to follow redirects by default (only applies to `KernelBrowser`). | `1` _(true)_ | +| `BROWSER_CATCH_EXCEPTIONS` | Whether to catch exceptions by default (only applies to `KernelBrowser`). | `1` _(true)_ | +| `BROWSER_SOURCE_DEBUG` | Whether to add request metadata to written source files (only applies to `KernelBrowser`). | `0` _(false)_ | +| `KERNEL_BROWSER_CLASS` | `KernelBrowser` class to use. | `Zenstruck\Browser\KernelBrowser` | +| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` | +| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ | +| `BROWSER_ALWAYS_START_WEBSERVER` | Always start a webserver configured for your current test env before running tests (only applies to `PantherBrowser`). | `0` _(false)_ | ## Extending @@ -818,9 +827,10 @@ Then, depending on the implementation you extended from, set the appropriate env For the example above, you would set `KERNEL_BROWSER_CLASS=App\Tests\AppBrowser`. -**TIP**: Create a base functional test case so all your tests can use your -custom browser and use the `@method` annotation to ensure your tests can -autocomplete your custom methods: +> [!TIP] +> Create a base functional test case so all your tests can use your +> custom browser and use the `@method` annotation to ensure your tests can +> autocomplete your custom methods: ```php namespace App\Tests; diff --git a/src/Browser/Test/HasBrowser.php b/src/Browser/Test/HasBrowser.php index 0bc8f67..2e985bb 100644 --- a/src/Browser/Test/HasBrowser.php +++ b/src/Browser/Test/HasBrowser.php @@ -64,6 +64,11 @@ protected function pantherBrowser(array $options = [], array $kernelOptions = [] 'console_log_dir' => $_SERVER['BROWSER_CONSOLE_LOG_DIR'] ?? './var/browser/console-logs', ]; + if ($_SERVER['BROWSER_ALWAYS_START_WEBSERVER'] ?? null) { + $_SERVER['PANTHER_APP_ENV'] = $_SERVER['APP_ENV'] ?? 'test'; // use current environment + $_SERVER['SYMFONY_PROJECT_DEFAULT_ROUTE_URL'] = ''; // ignore existing server running with Symfony CLI + } + if (self::$primaryPantherClient) { $browser = new $class(static::createAdditionalPantherClient(), $browserOptions); } else { From 9603f3dab8377ae3b341e653a8e61e15734b6336 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sun, 20 Oct 2024 19:04:59 -0400 Subject: [PATCH 07/10] changelog: update [skip ci] --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fc49a..e0b7286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +## [v1.9.0](https://github.com/zenstruck/browser/releases/tag/v1.9.0) + +October 20th, 2024 - [v1.8.1...v1.9.0](https://github.com/zenstruck/browser/compare/v1.8.1...v1.9.0) + +* 6175462 feat: add `BROWSER_ALWAYS_START_WEBSERVER` env var (#156) by @kbond +* d3a52e9 feat: deprecate foundry integration (#154) by @kbond +* 3b4d4a4 minor: fix tests (#154) by @kbond +* d90bad9 minor: sca (#154) by @kbond + ## [v1.8.1](https://github.com/zenstruck/browser/releases/tag/v1.8.1) February 21st, 2024 - [v1.8.0...v1.8.1](https://github.com/zenstruck/browser/compare/v1.8.0...v1.8.1) From 53bbc83504565e0c0c0c866f137f07fdc2a71c8e Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 5 Nov 2024 07:21:39 -0500 Subject: [PATCH 08/10] 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(); } From a1518531749b157347de60eef2a0a6f5fbd97b97 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 5 Nov 2024 07:21:53 -0500 Subject: [PATCH 09/10] changelog: update [skip ci] --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b7286..e4cd0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## [v1.9.1](https://github.com/zenstruck/browser/releases/tag/v1.9.1) + +November 5th, 2024 - [v1.9.0...v1.9.1](https://github.com/zenstruck/browser/compare/v1.9.0...v1.9.1) + +* 53bbc83 minor: unpack Foundry 2 proxies (#160) by @kbond + ## [v1.9.0](https://github.com/zenstruck/browser/releases/tag/v1.9.0) October 20th, 2024 - [v1.8.1...v1.9.0](https://github.com/zenstruck/browser/compare/v1.8.1...v1.9.0) From 28b7e1a80ae320517c0d3abb15b7ac799a053f02 Mon Sep 17 00:00:00 2001 From: kbond Date: Tue, 5 Nov 2024 12:22:24 +0000 Subject: [PATCH 10/10] bot: fix cs [skip ci] --- src/Browser/KernelBrowser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Browser/KernelBrowser.php b/src/Browser/KernelBrowser.php index c715fda..3082632 100644 --- a/src/Browser/KernelBrowser.php +++ b/src/Browser/KernelBrowser.php @@ -22,7 +22,7 @@ use Zenstruck\Callback\Parameter; use Zenstruck\Foundry\Factory; use Zenstruck\Foundry\Persistence\Proxy; -use Zenstruck\Foundry\Proxy As LegacyProxy; +use Zenstruck\Foundry\Proxy as LegacyProxy; /** * @author Kevin Bond