feat: moves visit to the core

This commit is contained in:
Nuno Maduro
2025-06-28 18:18:26 +01:00
parent a22013a7d3
commit 0bc3219a2b
7 changed files with 70 additions and 3 deletions

View File

@ -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.
*

View File

@ -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<int, string>|string
*
* @param TUrl $url
* @param array<string, mixed> $options
* @return (TUrl is array<int, string> ? 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);
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Pest\Installers;
use Pest\Support\View;
final readonly class PluginBrowser
{
public static function install(): void
{
View::render('installers/plugin-browser');
}
}

View File

@ -180,7 +180,7 @@ final class TestCall // @phpstan-ignore-line
/**
* Runs the current test multiple times with each item of the given `iterable`.
*
* @param Closure|iterable<array-key, mixed>|string $data
* @param Closure|iterable<array-key, mixed>|string $data
*/
public function with(Closure|iterable|string ...$data): self
{

View File

@ -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