added countries support expanded for ISO 3166 standard merged in new support

This commit is contained in:
Mark Gregory
2026-06-15 11:00:14 +01:00
parent 4099be7770
commit 96e0d60355
10 changed files with 187 additions and 65 deletions
+58 -14
View File
@@ -5,12 +5,14 @@ namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
use Laravel\Dusk\TestCase as BaseTestCase;
use PHPUnit\Framework\Attributes\BeforeClass;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*/
@@ -18,6 +20,7 @@ abstract class DuskTestCase extends BaseTestCase
public static function prepare(): void
{
if (! static::runningInSail()) {
static::ensureChromeDriverBinaryAlias();
static::startChromeDriver(['--port=9515']);
}
}
@@ -27,22 +30,63 @@ abstract class DuskTestCase extends BaseTestCase
*/
protected function driver(): RemoteWebDriver
{
$options = (new ChromeOptions)->addArguments(collect([
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
$options = (new ChromeOptions())->addArguments([
'--disable-gpu',
'--headless=new',
'--window-size=1920,1080',
'--no-sandbox',
'--disable-dev-shm-usage',
'--disable-search-engine-choice-screen',
'--disable-smooth-scrolling',
])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
return $items->merge([
'--disable-gpu',
'--headless=new',
]);
})->all());
]);
return RemoteWebDriver::create(
$_ENV['DUSK_DRIVER_URL'] ?? env('DUSK_DRIVER_URL') ?? 'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
$_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options)
);
}
/**
* Dusk may install a differently named macOS Apple Silicon binary.
* Laravel Dusk still asks for chromedriver-mac-arm, so create that alias safely.
*/
private static function ensureChromeDriverBinaryAlias(): void
{
$binDirectory = base_path('vendor/laravel/dusk/bin');
$expected = $binDirectory.'/chromedriver-mac-arm';
if (is_file($expected)) {
@chmod($expected, 0755);
return;
}
if (! is_dir($binDirectory)) {
@mkdir($binDirectory, 0755, true);
}
try {
Artisan::call('dusk:chrome-driver');
} catch (\Throwable) {
// Continue and inspect whatever files are available locally.
}
$candidates = array_values(array_filter(glob($binDirectory.'/chromedriver*') ?: [], static function (string $path) use ($expected): bool {
return is_file($path)
&& $path !== $expected
&& ! str_ends_with($path, '.zip')
&& ! str_ends_with($path, '.txt');
}));
usort($candidates, static function (string $left, string $right): int {
$score = static fn (string $path): int => str_contains($path, 'mac-arm64') ? 0
: (str_contains($path, 'mac-arm') ? 1
: (str_contains($path, 'mac') ? 2 : 3));
return $score($left) <=> $score($right);
});
if ($candidates !== []) {
@copy($candidates[0], $expected);
@chmod($expected, 0755);
}
}
}