From 468fcb93d88c11039feb330e358c73e239a33d6e Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 21 Jul 2023 21:53:12 +0800 Subject: [PATCH 1/2] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 8 ++++++++ src/UpdateCommand.php | 2 +- src/helpers.php | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/helpers.php diff --git a/composer.json b/composer.json index 5d1cd74..2b78f8d 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/UpdateCommand.php b/src/UpdateCommand.php index 2f91a43..95816ab 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -134,7 +134,7 @@ protected function rename(string $binary, string $os): void throw new RuntimeException("Unable to rename {$binary} without --install-dir"); } - $newName = array_reverse(explode(DIRECTORY_SEPARATOR, str_replace('chromedriver', 'chromedriver-'.$os, $binary), 2))[0]; + $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..8eb065f --- /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); +} From e015d047e9db847f445f4f910650949f931f6770 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 21 Jul 2023 22:05:07 +0800 Subject: [PATCH 2/2] wip Signed-off-by: Mior Muhammad Zaki --- src/DetectCommand.php | 11 +++++++---- tests/HelpersTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/HelpersTest.php diff --git a/src/DetectCommand.php b/src/DetectCommand.php index c7d3f38..21e48cf 100644 --- a/src/DetectCommand.php +++ b/src/DetectCommand.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($autoUpdate || $io->confirm('Do you want to update ChromeDriver?')) { - $this->updateChromeDriver($output, $driverDirectory, $chromeVersions['major']); + $this->updateChromeDriver($input, $output, $driverDirectory, $chromeVersions['major']); } } @@ -73,18 +73,21 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * 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/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']; + } +}