diff --git a/src/Chrome/ChromeProcess.php b/src/Chrome/ChromeProcess.php index 1fe1c5abe..6ec0f2598 100644 --- a/src/Chrome/ChromeProcess.php +++ b/src/Chrome/ChromeProcess.php @@ -39,9 +39,11 @@ public function toProcess(array $arguments = []) if ($this->driver) { $driver = $this->driver; } elseif ($this->onWindows()) { - $driver = __DIR__.'/../../bin/chromedriver-win.exe'; - } elseif ($this->onMac()) { - $driver = __DIR__.'/../../bin/chromedriver-mac'; + $driver = realpath(__DIR__.'/../../bin/chromedriver-win.exe'); + } elseif ($this->onIntelMac()) { + $driver = realpath(__DIR__.'/../../bin/chromedriver-mac-intel'); + } elseif ($this->onArmMac()) { + $driver = realpath(__DIR__.'/../../bin/chromedriver-mac-arm'); } else { $driver = __DIR__.'/../../bin/chromedriver-linux'; } @@ -77,7 +79,7 @@ protected function process(array $arguments = []) */ protected function chromeEnvironment() { - if ($this->onMac() || $this->onWindows()) { + if ($this->onIntelMac() || $this->onArmMac() || $this->onWindows()) { return []; } @@ -95,12 +97,22 @@ protected function onWindows() } /** - * Determine if Dusk is running on Mac. + * Determine if Dusk is running on Mac x86_64. * * @return bool */ - protected function onMac() + protected function onIntelMac() { - return OperatingSystem::onMac(); + return OperatingSystem::onIntelMac(); + } + + /** + * Determine if Dusk is running on Mac arm64. + * + * @return bool + */ + protected function onArmMac() + { + return OperatingSystem::onArmMac(); } } diff --git a/src/Console/ChromeDriverCommand.php b/src/Console/ChromeDriverCommand.php index 651d38362..d93e80c77 100644 --- a/src/Console/ChromeDriverCommand.php +++ b/src/Console/ChromeDriverCommand.php @@ -58,7 +58,8 @@ class ChromeDriverCommand extends Command */ protected $slugs = [ 'linux' => 'linux64', - 'mac' => 'mac64', + 'mac-intel' => 'mac64', + 'mac-arm' => 'mac64_m1', 'win' => 'win32', ]; @@ -116,7 +117,10 @@ class ChromeDriverCommand extends Command '/usr/bin/chromium --version', '/usr/bin/google-chrome-stable --version', ], - 'mac' => [ + 'mac-intel' => [ + '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version', + ], + 'mac-arm' => [ '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version', ], 'win' => [ diff --git a/src/OperatingSystem.php b/src/OperatingSystem.php index d32a99c84..b0244a581 100644 --- a/src/OperatingSystem.php +++ b/src/OperatingSystem.php @@ -13,7 +13,15 @@ class OperatingSystem */ public static function id() { - return static::onWindows() ? 'win' : (static::onMac() ? 'mac' : 'linux'); + if (static::onWindows()) { + return 'win'; + } elseif (static::onIntelMac()) { + return 'mac-intel'; + } elseif (static::onArmMac()) { + return 'mac-arm'; + } + + return 'linux'; } /** @@ -27,12 +35,22 @@ public static function onWindows() } /** - * Determine if the operating system is macOS. + * Determine if the operating system is macOS x86_64. + * + * @return bool + */ + public static function onIntelMac() + { + return PHP_OS === 'Darwin' && php_uname('m') === 'x86_64'; + } + + /** + * Determine if the operating system is macOS arm64. * * @return bool */ - public static function onMac() + public static function onArmMac() { - return PHP_OS === 'Darwin'; + return PHP_OS === 'Darwin' && php_uname('m') === 'arm64'; } } diff --git a/tests/ChromeProcessTest.php b/tests/ChromeProcessTest.php index 2ab0ff6af..b9335d2f8 100644 --- a/tests/ChromeProcessTest.php +++ b/tests/ChromeProcessTest.php @@ -28,12 +28,21 @@ public function test_build_process_for_windows() } } - public function test_build_process_for_darwin() + public function test_build_process_for_darwin_intel() { try { - (new ChromeProcessDarwin)->toProcess(); + (new ChromeProcessDarwinIntel)->toProcess(); } catch (RuntimeException $exception) { - $this->assertStringContainsString('chromedriver-mac', $exception->getMessage()); + $this->assertStringContainsString('chromedriver-mac-intel', $exception->getMessage()); + } + } + + public function test_build_process_for_darwin_arm() + { + try { + (new ChromeProcessDarwinArm)->toProcess(); + } catch (RuntimeException $exception) { + $this->assertStringContainsString('chromedriver-mac-arm', $exception->getMessage()); } } @@ -63,9 +72,9 @@ protected function onWindows() } } -class ChromeProcessDarwin extends ChromeProcess +class ChromeProcessDarwinIntel extends ChromeProcess { - protected function onMac() + protected function onIntelMac() { return true; } @@ -76,9 +85,32 @@ protected function onWindows() } } +class ChromeProcessDarwinArm extends ChromeProcess +{ + protected function onArmMac() + { + return true; + } + + protected function onIntelMac() + { + return false; + } + + protected function onWindows() + { + return false; + } +} + class ChromeProcessLinux extends ChromeProcess { - protected function onMac() + protected function onArmMac() + { + return false; + } + + protected function onIntelMac() { return false; }