From 0bc3219a2b3efe72275e8ed0ccc1dc9765178e65 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sat, 28 Jun 2025 18:18:26 +0100 Subject: [PATCH] feat: moves `visit` to the core --- composer.json | 3 ++- resources/views/installers/plugin-browser.php | 17 ++++++++++++ src/Configuration.php | 8 ++++++ src/Functions.php | 26 +++++++++++++++++++ src/Installers/PluginBrowser.php | 15 +++++++++++ src/PendingCalls/TestCall.php | 2 +- src/Pest.php | 2 +- 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 resources/views/installers/plugin-browser.php create mode 100644 src/Installers/PluginBrowser.php diff --git a/composer.json b/composer.json index 516e62b9..80354710 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^8.3.0", "brianium/paratest": "^7.10.2", - "nunomaduro/collision": "^8.8.1", + "nunomaduro/collision": "^8.8.2", "nunomaduro/termwind": "^2.3.1", "pestphp/pest-plugin": "^4.0.0", "pestphp/pest-plugin-arch": "^4.0.0", @@ -55,6 +55,7 @@ }, "require-dev": { "pestphp/pest-dev-tools": "^4.0.0", + "pestphp/pest-plugin-browser": "^4.0.0", "pestphp/pest-plugin-type-coverage": "^4.0.0", "symfony/process": "^7.3.0" }, diff --git a/resources/views/installers/plugin-browser.php b/resources/views/installers/plugin-browser.php new file mode 100644 index 00000000..28288ab0 --- /dev/null +++ b/resources/views/installers/plugin-browser.php @@ -0,0 +1,17 @@ +
+

+ Using the visit() function requires the Pest Plugin Browser to be installed. + + Run: +

+ +
+ - + composer require pestphp/pest-plugin-browser:^4.0 --dev +
+ +
+ - + npx playwright install +
+
diff --git a/src/Configuration.php b/src/Configuration.php index c504aa65..fb4f45a4 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -102,6 +102,14 @@ final readonly class Configuration return Configuration\Project::getInstance(); } + /** + * Gets the browser configuration. + */ + public function browser(): Browser\Configuration + { + return new Browser\Configuration; + } + /** * Proxies calls to the uses method. * diff --git a/src/Functions.php b/src/Functions.php index f17ea15c..1702f94a 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -2,11 +2,14 @@ declare(strict_types=1); +use Pest\Browser\Api\ArrayablePendingAwaitablePage; +use Pest\Browser\Api\PendingAwaitablePage; use Pest\Concerns\Expectable; use Pest\Configuration; use Pest\Exceptions\AfterAllWithinDescribe; use Pest\Exceptions\BeforeAllWithinDescribe; use Pest\Expectation; +use Pest\Installers\PluginBrowser; use Pest\Mutate\Contracts\MutationTestRunner; use Pest\Mutate\Repositories\ConfigurationRepository; use Pest\PendingCalls\AfterEachCall; @@ -303,3 +306,26 @@ if (! function_exists('fixture')) { return $fileRealPath; } } + +if (! function_exists('visit')) { + /** + * Browse to the given URL. + * + * @template TUrl of array|string + * + * @param TUrl $url + * @param array $options + * @return (TUrl is array ? ArrayablePendingAwaitablePage : PendingAwaitablePage) + */ + function visit(array|string $url, array $options = []): ArrayablePendingAwaitablePage|PendingAwaitablePage + { + if (! class_exists(\Pest\Browser\Configuration::class)) { + PluginBrowser::install(); + + exit(0); + } + + // @phpstan-ignore-next-line + return test()->visit($url, $options); + } +} diff --git a/src/Installers/PluginBrowser.php b/src/Installers/PluginBrowser.php new file mode 100644 index 00000000..2d36ed3d --- /dev/null +++ b/src/Installers/PluginBrowser.php @@ -0,0 +1,15 @@ +|string $data + * @param Closure|iterable|string $data */ public function with(Closure|iterable|string ...$data): self { diff --git a/src/Pest.php b/src/Pest.php index 47af9ee1..7741ff4d 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '4.0.0-alpha.3'; + return '4.0.0-alpha.4'; } function testDirectory(string $file = ''): string