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/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']); 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) 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', ]; } }