diff --git a/composer.json b/composer.json index 344355a..c120c42 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,14 @@ "autoload": { "psr-4": { "Orchestra\\DuskUpdater\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Orchestra\\DuskUpdater\\Tests\\": "tests/" } }, "require": { diff --git a/src/DetectCommand.php b/src/DetectCommand.php index 9647140..d37a524 100644 --- a/src/DetectCommand.php +++ b/src/DetectCommand.php @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($autoUpdate || $io->confirm('Do you want to update ChromeDriver?')) { - $this->updateChromeDriver($output, $driverDirectory, $chromeVersions['major']); + $this->updateChromeDriver($input, $output, $driverDirectory, $chromeVersions['major']); } } @@ -71,18 +71,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * Update ChromeDriver. */ - protected function updateChromeDriver(OutputInterface $output, string $directory, int $version): int + protected function updateChromeDriver(InputInterface $input, OutputInterface $output, string $directory, int $version): int { /** @var \Symfony\Component\Console\Application $console */ $console = $this->getApplication(); $command = $console->find('update'); - $arguments = [ + $arguments = array_merge([ 'command' => 'update', 'version' => $version, '--install-dir' => $directory, - ]; + ], array_filter([ + '--proxy' => $input->getOption('proxy'), + '--ssl-no-verify' => $input->getOption('ssl-no-verify'), + ])); return $command->run(new ArrayInput($arguments), $output); } diff --git a/src/UpdateCommand.php b/src/UpdateCommand.php index 86e569b..6f01d16 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -134,9 +134,7 @@ protected function rename(string $binary, string $os): void throw new RuntimeException("Unable to rename {$binary} without --install-dir"); } - $newName = strpos($binary, DIRECTORY_SEPARATOR) >= 0 - ? array_reverse(explode(DIRECTORY_SEPARATOR, str_replace('chromedriver', 'chromedriver-'.$os, $binary), 2))[0] - : str_replace('chromedriver', 'chromedriver-'.$os, $binary); + $newName = chromedriver_binary_filename($binary, $os); rename($this->directory.$binary, $this->directory.$newName); diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..b1cda6f --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,10 @@ + 0 + ? array_reverse(explode(DIRECTORY_SEPARATOR, str_replace('chromedriver', 'chromedriver-'.$os, $binary), 2))[0] + : str_replace('chromedriver', 'chromedriver-'.$os, $binary); +} diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php new file mode 100644 index 0000000..169f35e --- /dev/null +++ b/tests/HelpersTest.php @@ -0,0 +1,30 @@ +assertSame(chromedriver_binary_filename($given, $os), $expected); + } + + public static function binaryFileDataProvider() + { + yield ['linux', 'chromedriver', 'chromedriver-linux']; + yield ['mac-intel', 'chromedriver', 'chromedriver-mac-intel']; + yield ['mac-arm', 'chromedriver', 'chromedriver-mac-arm']; + yield ['win32', 'chromedriver.exe', 'chromedriver-win32.exe']; + + yield ['linux', 'chromedriver-115'.DIRECTORY_SEPARATOR.'chromedriver', 'chromedriver-linux']; + yield ['mac-intel', 'chromedriver-115'.DIRECTORY_SEPARATOR.'chromedriver', 'chromedriver-mac-intel']; + yield ['mac-arm', 'chromedriver-115'.DIRECTORY_SEPARATOR.'chromedriver', 'chromedriver-mac-arm']; + yield ['win32', 'chromedriver-115'.DIRECTORY_SEPARATOR.'chromedriver.exe', 'chromedriver-win32.exe']; + } +}