-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1.x: minor: unpack Foundry 2 proxies (#160) feat: add `BROWSER_ALWAYS_START_WEBSERVER` env var (#156) feat: deprecate foundry integration minor: fix tests
- Loading branch information
Showing
10 changed files
with
95 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ | |
use Zenstruck\Callback\Parameter; | ||
use Zenstruck\Dom\Selector; | ||
use Zenstruck\Foundry\Factory; | ||
use Zenstruck\Foundry\Proxy; | ||
use Zenstruck\Foundry\Persistence\Proxy; | ||
use Zenstruck\Foundry\Proxy as LegacyProxy; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
@@ -135,18 +136,23 @@ final public function withProfiling(): self | |
} | ||
|
||
/** | ||
* @param UserInterface|Proxy<UserInterface>|Factory<UserInterface> $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 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) { | ||
|
@@ -159,7 +165,7 @@ public function actingAs(object $user, ?string $firewall = null): self | |
} | ||
|
||
/** | ||
* @param string|UserInterface|Proxy<UserInterface>|Factory<UserInterface>|null $as | ||
* @param string|UserInterface|null $as | ||
* | ||
* @return static | ||
*/ | ||
|
@@ -179,12 +185,17 @@ 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 LegacyProxy) { // @phpstan-ignore-line | ||
$as = $as->object(); // @phpstan-ignore-line | ||
} | ||
|
||
if ($as instanceof Proxy) { | ||
$as = $as->object(); | ||
if ($as instanceof Proxy) { // @phpstan-ignore-line | ||
$as = $as->_real(); // @phpstan-ignore-line | ||
} | ||
|
||
if ($as instanceof UserInterface) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
|
@@ -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 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
final class KernelBrowserAuthenticationTest extends KernelTestCase | ||
{ | ||
use Factories, HasBrowser; | ||
use HasBrowser; | ||
|
||
/** | ||
* @test | ||
|
@@ -41,54 +38,20 @@ 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 | ||
*/ | ||
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() | ||
->actingAs($user) | ||
->assertAuthenticated() | ||
->assertAuthenticated($username) | ||
->assertAuthenticated($user) | ||
->assertAuthenticated($factory) | ||
->assertAuthenticated($proxy) | ||
->visit('/user') | ||
->assertAuthenticated() | ||
->assertAuthenticated($username) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters