Skip to content

Commit 92c5c8f

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: minor: unpack Foundry 2 proxies (#160) feat: add `BROWSER_ALWAYS_START_WEBSERVER` env var (#156) feat: deprecate foundry integration minor: fix tests
2 parents 278ac33 + 28b7e1a commit 92c5c8f

10 files changed

+95
-102
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
## [v1.9.1](https://github.com/zenstruck/browser/releases/tag/v1.9.1)
4+
5+
November 5th, 2024 - [v1.9.0...v1.9.1](https://github.com/zenstruck/browser/compare/v1.9.0...v1.9.1)
6+
7+
* 53bbc83 minor: unpack Foundry 2 proxies (#160) by @kbond
8+
9+
## [v1.9.0](https://github.com/zenstruck/browser/releases/tag/v1.9.0)
10+
11+
October 20th, 2024 - [v1.8.1...v1.9.0](https://github.com/zenstruck/browser/compare/v1.8.1...v1.9.0)
12+
13+
* 6175462 feat: add `BROWSER_ALWAYS_START_WEBSERVER` env var (#156) by @kbond
14+
* d3a52e9 feat: deprecate foundry integration (#154) by @kbond
15+
* 3b4d4a4 minor: fix tests (#154) by @kbond
16+
* d90bad9 minor: sca (#154) by @kbond
17+
318
## [v1.8.1](https://github.com/zenstruck/browser/releases/tag/v1.8.1)
419

520
February 21st, 2024 - [v1.8.0...v1.8.1](https://github.com/zenstruck/browser/compare/v1.8.0...v1.8.1)

README.md

+22-17
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
```
@@ -462,7 +458,15 @@ $json = $browser
462458
463459
### PantherBrowser
464460

465-
*The `PantherBrowser` is experimental in 1.0 and may be subject to BC Breaks.*
461+
> [!NOTE]
462+
> The `PantherBrowser` is experimental in 1.0 and may be subject to BC Breaks.
463+
464+
> [!TIP]
465+
> By default, Panther will not start a web server if it detects one already running
466+
> with the Symfony CLI. This is likely running in your `dev` environment and will cause
467+
> unexpected test failures. Set the env variable `BROWSER_ALWAYS_START_WEBSERVER=1`
468+
> to always start a webserver configured for your current test env when running
469+
> Panther tests.
466470
467471
This browser has the following extra methods:
468472

@@ -666,17 +670,18 @@ $browser->assertSeeElement(ProductLinkSelector('Product 1', 'Edit'));
666670

667671
There are several environment variables available to configure:
668672

669-
| Variable | Description | Default |
670-
|----------------------------|--------------------------------------------------------------------------------------------|------------------------------------|
671-
| `BROWSER_SOURCE_DIR` | Directory to save source files to. | `./var/browser/source` |
672-
| `BROWSER_SCREENSHOT_DIR` | Directory to save screenshots to (only applies to `PantherBrowser`). | `./var/browser/screenshots` |
673-
| `BROWSER_CONSOLE_LOG_DIR` | Directory to save javascript console logs to (only applies to `PantherBrowser`). | `./var/browser/console-logs` |
674-
| `BROWSER_FOLLOW_REDIRECTS` | Whether to follow redirects by default (only applies to `KernelBrowser`). | `1` _(true)_ |
675-
| `BROWSER_CATCH_EXCEPTIONS` | Whether to catch exceptions by default (only applies to `KernelBrowser`). | `1` _(true)_ |
676-
| `BROWSER_SOURCE_DEBUG` | Whether to add request metadata to written source files (only applies to `KernelBrowser`). | `0` _(false)_ |
677-
| `KERNEL_BROWSER_CLASS` | `KernelBrowser` class to use. | `Zenstruck\Browser\KernelBrowser` |
678-
| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` |
679-
| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ |
673+
| Variable | Description | Default |
674+
|----------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------|
675+
| `BROWSER_SOURCE_DIR` | Directory to save source files to. | `./var/browser/source` |
676+
| `BROWSER_SCREENSHOT_DIR` | Directory to save screenshots to (only applies to `PantherBrowser`). | `./var/browser/screenshots` |
677+
| `BROWSER_CONSOLE_LOG_DIR` | Directory to save javascript console logs to (only applies to `PantherBrowser`). | `./var/browser/console-logs` |
678+
| `BROWSER_FOLLOW_REDIRECTS` | Whether to follow redirects by default (only applies to `KernelBrowser`). | `1` _(true)_ |
679+
| `BROWSER_CATCH_EXCEPTIONS` | Whether to catch exceptions by default (only applies to `KernelBrowser`). | `1` _(true)_ |
680+
| `BROWSER_SOURCE_DEBUG` | Whether to add request metadata to written source files (only applies to `KernelBrowser`). | `0` _(false)_ |
681+
| `KERNEL_BROWSER_CLASS` | `KernelBrowser` class to use. | `Zenstruck\Browser\KernelBrowser` |
682+
| `PANTHER_BROWSER_CLASS` | `PantherBrowser` class to use. | `Zenstruck\Browser\PantherBrowser` |
683+
| `PANTHER_NO_HEADLESS` | Disable headless-mode and allow usage of `PantherBrowser::pause()`. | `0` _(false)_ |
684+
| `BROWSER_ALWAYS_START_WEBSERVER` | Always start a webserver configured for your current test env before running tests (only applies to `PantherBrowser`). | `0` _(false)_ |
680685

681686
## Extending
682687

composer.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
},
2424
"require-dev": {
2525
"dbrekelmans/bdi": "^1.0",
26-
"justinrainbow/json-schema": "^5.2.13",
26+
"justinrainbow/json-schema": "^5.3",
2727
"mtdowling/jmespath.php": "^2.6",
2828
"phpstan/phpstan": "^1.4",
29-
"phpunit/phpunit": "^9.6|^10.4",
30-
"symfony/mime": "^6.4|^7.0",
31-
"symfony/panther": "^2.1.0",
29+
"phpunit/phpunit": "^9.6.21|^10.4",
30+
"symfony/mime": "^5.4|^6.0|^7.0",
31+
"symfony/panther": "^1.1|^2.0.1",
3232
"symfony/phpunit-bridge": "^6.0|^7.0",
33-
"symfony/security-bundle": "^6.4|^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

+22-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
use Zenstruck\Callback\Parameter;
2424
use Zenstruck\Dom\Selector;
2525
use Zenstruck\Foundry\Factory;
26-
use Zenstruck\Foundry\Proxy;
26+
use Zenstruck\Foundry\Persistence\Proxy;
27+
use Zenstruck\Foundry\Proxy as LegacyProxy;
2728

2829
/**
2930
* @author Kevin Bond <[email protected]>
@@ -135,18 +136,23 @@ final public function withProfiling(): self
135136
}
136137

137138
/**
138-
* @param UserInterface|Proxy<UserInterface>|Factory<UserInterface> $user
139+
* @param UserInterface $user
139140
*
140141
* @return static
141142
*/
142143
public function actingAs(object $user, ?string $firewall = null): self
143144
{
144-
if ($user instanceof Factory) {
145-
$user = $user->create();
145+
if ($user instanceof Factory) { // @phpstan-ignore-line
146+
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to actingAs() is deprecated, pass the created object instead.');
147+
$user = $user->create(); // @phpstan-ignore-line
146148
}
147149

148-
if ($user instanceof Proxy) {
149-
$user = $user->object();
150+
if ($user instanceof LegacyProxy) { // @phpstan-ignore-line
151+
$user = $user->object(); // @phpstan-ignore-line
152+
}
153+
154+
if ($user instanceof Proxy) { // @phpstan-ignore-line
155+
$user = $user->_real(); // @phpstan-ignore-line
150156
}
151157

152158
if (!$user instanceof UserInterface) {
@@ -159,7 +165,7 @@ public function actingAs(object $user, ?string $firewall = null): self
159165
}
160166

161167
/**
162-
* @param string|UserInterface|Proxy<UserInterface>|Factory<UserInterface>|null $as
168+
* @param string|UserInterface|null $as
163169
*
164170
* @return static
165171
*/
@@ -179,12 +185,17 @@ public function assertAuthenticated($as = null): self
179185
return $this;
180186
}
181187

182-
if ($as instanceof Factory) {
183-
$as = $as->create();
188+
if ($as instanceof Factory) { // @phpstan-ignore-line
189+
trigger_deprecation('zenstruck/browser', '1.9', 'Passing a Factory to assertAuthenticated() is deprecated, pass the created object instead.');
190+
$as = $as->create(); // @phpstan-ignore-line
191+
}
192+
193+
if ($as instanceof LegacyProxy) { // @phpstan-ignore-line
194+
$as = $as->object(); // @phpstan-ignore-line
184195
}
185196

186-
if ($as instanceof Proxy) {
187-
$as = $as->object();
197+
if ($as instanceof Proxy) { // @phpstan-ignore-line
198+
$as = $as->_real(); // @phpstan-ignore-line
188199
}
189200

190201
if ($as instanceof UserInterface) {

src/Browser/Test/HasBrowser.php

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ protected function pantherBrowser(array $options = [], array $kernelOptions = []
6464
'console_log_dir' => $_SERVER['BROWSER_CONSOLE_LOG_DIR'] ?? './var/browser/console-logs',
6565
];
6666

67+
if ($_SERVER['BROWSER_ALWAYS_START_WEBSERVER'] ?? null) {
68+
$_SERVER['PANTHER_APP_ENV'] = $_SERVER['APP_ENV'] ?? 'test'; // use current environment
69+
$_SERVER['SYMFONY_PROJECT_DEFAULT_ROUTE_URL'] = ''; // ignore existing server running with Symfony CLI
70+
}
71+
6772
if (self::$primaryPantherClient) {
6873
$browser = new $class(static::createAdditionalPantherClient(), $browserOptions);
6974
} else {

src/Browser/Test/LegacyExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static function normalizeTestName(string $name): string
122122
\preg_match('#^(?<test>[\w:\\\]+) with data set "(?<dataset>.*)"#', $name, $matches);
123123
}
124124

125-
$normalized = \strtr($matches['test'], '\\:', '-_');
125+
$normalized = \strtr($matches['test'], '\\:', '-_'); // @phpstan-ignore-line
126126

127127
if (isset($matches['dataset'])) {
128128
$normalized .= '__data-set-'.\preg_replace('/\W+/', '-', $matches['dataset']);

tests/Fixture/Kernel.php

-5
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/HttpOptionsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function json_ajax_constructor_with_no_value(): void
196196
*/
197197
public function create_with_self(): void
198198
{
199-
$options = new class() extends HttpOptions {};
199+
$options = new class extends HttpOptions {};
200200

201201
$this->assertSame($options, HttpOptions::create($options));
202202
}

tests/KernelBrowserAuthenticationTest.php

+1-38
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)

tests/NormalizationTest.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public static function namesProvider(): \Generator
4242
$baseTemplate = 'error_'.__METHOD__;
4343

4444
yield 'test name without datasets' => [
45-
'test name' => __METHOD__,
46-
'expected output' => \strtr($baseTemplate, '\\:', '-_').'__0',
45+
'testName' => __METHOD__,
46+
'expectedOutput' => \strtr($baseTemplate, '\\:', '-_').'__0',
4747
];
4848

4949
$datasetTemplate = $baseTemplate.'__data-set-%s__0';
@@ -55,49 +55,49 @@ public static function namesProvider(): \Generator
5555
$numericOutput = \strtr($numericTemplate, '\\:', '-_');
5656

5757
yield 'phpunit 10 alpha' => [
58-
'test name' => __METHOD__.' with data set "test set"',
59-
'expected output' => $alphaOutput,
58+
'testName' => __METHOD__.' with data set "test set"',
59+
'expectedOutput' => $alphaOutput,
6060
];
6161
yield 'phpunit 10 numeric' => [
62-
'test name' => __METHOD__.' with data set #0',
63-
'expected output' => $numericOutput,
62+
'testName' => __METHOD__.' with data set #0',
63+
'expectedOutput' => $numericOutput,
6464
];
6565
yield 'legacy alpha' => [
66-
'test name' => __METHOD__.' with data set "test set" (test set)',
67-
'expected output' => $alphaOutput,
66+
'testName' => __METHOD__.' with data set "test set" (test set)',
67+
'expectedOutput' => $alphaOutput,
6868
];
6969
yield 'legacy numeric' => [
70-
'test name' => __METHOD__.' with data set #0 (test set)',
71-
'expected output' => $numericOutput,
70+
'testName' => __METHOD__.' with data set #0 (test set)',
71+
'expectedOutput' => $numericOutput,
7272
];
7373
}
7474

7575
public static function edgeCaseTestNames(): \Generator
7676
{
7777
$baseTemplate = \strtr('error_'.__METHOD__.'__data-set-', '\\:', '-_');
7878
yield 'self within moustache' => [
79-
'test name' => __METHOD__.' with data set "te{{self}}st" (test set)',
80-
'expected output' => $baseTemplate.'te-self-st__0',
79+
'testName' => __METHOD__.' with data set "te{{self}}st" (test set)',
80+
'expectedOutput' => $baseTemplate.'te-self-st__0',
8181
];
8282
yield 'double quoted with space' => [
83-
'test name' => __METHOD__.' with data set "_self.env.setCache("uri://host.net:2121") _self.env.loadTemplate("other-host")" (test set)',
84-
'expected output' => $baseTemplate.'_self-env-setCache-uri-host-net-2121-_self-env-loadTemplate-other-host-__0',
83+
'testName' => __METHOD__.' with data set "_self.env.setCache("uri://host.net:2121") _self.env.loadTemplate("other-host")" (test set)',
84+
'expectedOutput' => $baseTemplate.'_self-env-setCache-uri-host-net-2121-_self-env-loadTemplate-other-host-__0',
8585
];
8686
yield 'double quotes in moustache' => [
87-
'test name' => __METHOD__.' with data set "te{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}st"',
88-
'expected output' => $baseTemplate.'te-_self-env-registerUndefinedFilterCallback-exec-_self-env-getFilter-id-st__0',
87+
'testName' => __METHOD__.' with data set "te{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}st"',
88+
'expectedOutput' => $baseTemplate.'te-_self-env-registerUndefinedFilterCallback-exec-_self-env-getFilter-id-st__0',
8989
];
9090
yield 'escaped simple quote' => [
91-
'test name' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"',
92-
'expected output' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0',
93-
];
91+
'testName' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"',
92+
'expectedOutput' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0',
93+
];
9494
yield 'single quote for array index access' => [
95-
'test name' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"',
96-
'expected output' => $baseTemplate.'te-id-filter-system-st__0',
95+
'testName' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"',
96+
'expectedOutput' => $baseTemplate.'te-id-filter-system-st__0',
9797
];
9898
yield 'numeric array access' => [
99-
'test name' => __METHOD__.' with data set "te{{[0]|reduce(\'system\',\'id\')}}st"',
100-
'expected output' => $baseTemplate.'te-0-reduce-system-id-st__0',
99+
'testName' => __METHOD__.' with data set "te{{[0]|reduce(\'system\',\'id\')}}st"',
100+
'expectedOutput' => $baseTemplate.'te-0-reduce-system-id-st__0',
101101
];
102102
}
103103
}

0 commit comments

Comments
 (0)