Skip to content

Commit f3b2400

Browse files
committed
feat: deprecate foundry integration
1 parent 3b4d4a4 commit f3b2400

File tree

5 files changed

+17
-60
lines changed

5 files changed

+17
-60
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ $browser
320320
// authenticate a user for subsequent actions
321321
->actingAs($user) // \Symfony\Component\Security\Core\User\UserInterface
322322

323-
// If using zenstruck/foundry, you can pass a factory/proxy
324-
->actingAs(UserFactory::new())
325-
326323
// fail if authenticated
327324
->assertNotAuthenticated()
328325

@@ -332,8 +329,7 @@ $browser
332329
// fails if NOT authenticated as "kbond"
333330
->assertAuthenticated('kbond')
334331

335-
// \Symfony\Component\Security\Core\User\UserInterface or, if using
336-
// zenstruck/foundry, you can pass a factory/proxy
332+
// \Symfony\Component\Security\Core\User\UserInterface
337333
->assertAuthenticated($user)
338334
;
339335
```

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"symfony/mime": "^5.4|^6.0|^7.0",
3131
"symfony/panther": "^1.1|^2.0.1",
3232
"symfony/phpunit-bridge": "^6.0|^7.0",
33-
"symfony/security-bundle": "^5.4|^6.0|^7.0",
34-
"zenstruck/foundry": "^1.30"
33+
"symfony/security-bundle": "^5.4|^6.0|^7.0"
3534
},
3635
"suggest": {
3736
"justinrainbow/json-schema": "Json schema validator. Needed to use Json::assertMatchesSchema().",

src/Browser/KernelBrowser.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,20 @@ final public function withProfiling(): self
127127
}
128128

129129
/**
130-
* @param UserInterface|Proxy<UserInterface>|Factory<UserInterface> $user
130+
* @param UserInterface $user
131131
*
132132
* @return static
133133
*/
134134
public function actingAs(object $user, ?string $firewall = null): self
135135
{
136-
if ($user instanceof Factory) {
137-
$user = $user->create();
136+
if ($user instanceof Factory) { // @phpstan-ignore-line
137+
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to actingAs() is deprecated, pass the created object instead.');
138+
$user = $user->create(); // @phpstan-ignore-line
138139
}
139140

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

144146
if (!$user instanceof UserInterface) {
@@ -151,7 +153,7 @@ public function actingAs(object $user, ?string $firewall = null): self
151153
}
152154

153155
/**
154-
* @param string|UserInterface|Proxy<UserInterface>|Factory<UserInterface>|null $as
156+
* @param string|UserInterface|null $as
155157
*
156158
* @return static
157159
*/
@@ -171,12 +173,14 @@ public function assertAuthenticated($as = null): self
171173
return $this;
172174
}
173175

174-
if ($as instanceof Factory) {
175-
$as = $as->create();
176+
if ($as instanceof Factory) { // @phpstan-ignore-line
177+
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to assertAuthenticated() is deprecated, pass the created object instead.');
178+
$as = $as->create(); // @phpstan-ignore-line
176179
}
177180

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

182186
if ($as instanceof UserInterface) {

tests/Fixture/Kernel.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
2929
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
3030
use Symfony\Component\Security\Core\User\InMemoryUser;
31-
use Zenstruck\Foundry\ZenstruckFoundryBundle;
3231

3332
/**
3433
* @author Kevin Bond <[email protected]>
@@ -173,7 +172,6 @@ public function registerBundles(): iterable
173172
{
174173
yield new FrameworkBundle();
175174
yield new SecurityBundle();
176-
yield new ZenstruckFoundryBundle();
177175
}
178176

179177
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
@@ -209,9 +207,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
209207
}
210208

211209
$c->loadFromExtension('security', $security);
212-
$c->loadFromExtension('zenstruck_foundry', [
213-
'auto_refresh_proxies' => false,
214-
]);
215210
$c->register('logger', NullLogger::class); // disable logging
216211
}
217212

tests/KernelBrowserAuthenticationTest.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1818
use Symfony\Component\Security\Core\User\InMemoryUser;
1919
use Zenstruck\Browser\Test\HasBrowser;
20-
use Zenstruck\Foundry\Test\Factories;
21-
22-
use function Zenstruck\Foundry\anonymous;
2320

2421
/**
2522
* @author Kevin Bond <[email protected]>
2623
*/
2724
final class KernelBrowserAuthenticationTest extends KernelTestCase
2825
{
29-
use Factories, HasBrowser;
26+
use HasBrowser;
3027

3128
/**
3229
* @test
@@ -41,54 +38,20 @@ public function can_act_as_user(): void
4138
;
4239
}
4340

44-
/**
45-
* @test
46-
*/
47-
public function can_act_as_user_with_foundry_factory(): void
48-
{
49-
$user = anonymous(InMemoryUser::class, ['username' => 'kevin', 'password' => 'pass']);
50-
51-
$this->browser()
52-
->throwExceptions()
53-
->actingAs($user)
54-
->visit('/user')
55-
->assertSee('user: kevin/pass')
56-
;
57-
}
58-
59-
/**
60-
* @test
61-
*/
62-
public function can_act_as_user_with_foundry_proxy(): void
63-
{
64-
$user = anonymous(InMemoryUser::class)->create(['username' => 'kevin', 'password' => 'pass']);
65-
66-
$this->browser()
67-
->throwExceptions()
68-
->actingAs($user)
69-
->visit('/user')
70-
->assertSee('user: kevin/pass')
71-
;
72-
}
73-
7441
/**
7542
* @test
7643
*/
7744
public function can_make_authentication_assertions(): void
7845
{
7946
$username = 'kevin';
8047
$user = new InMemoryUser('kevin', 'pass');
81-
$factory = anonymous(InMemoryUser::class, ['username' => 'kevin', 'password' => 'pass']);
82-
$proxy = anonymous(InMemoryUser::class)->create(['username' => 'kevin', 'password' => 'pass']);
8348

8449
$this->browser()
8550
->assertNotAuthenticated()
8651
->actingAs($user)
8752
->assertAuthenticated()
8853
->assertAuthenticated($username)
8954
->assertAuthenticated($user)
90-
->assertAuthenticated($factory)
91-
->assertAuthenticated($proxy)
9255
->visit('/user')
9356
->assertAuthenticated()
9457
->assertAuthenticated($username)

0 commit comments

Comments
 (0)