Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jul 21, 2023
2 parents 75150f1 + e015d04 commit 0354868
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
"autoload": {
"psr-4": {
"Orchestra\\DuskUpdater\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Orchestra\\DuskUpdater\\Tests\\": "tests/"
}
},
"require": {
Expand Down
11 changes: 7 additions & 4 deletions src/DetectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

Expand All @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions src/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Orchestra\DuskUpdater;

function chromedriver_binary_filename(string $binary, string $os): string
{
return strpos($binary, DIRECTORY_SEPARATOR) > 0
? array_reverse(explode(DIRECTORY_SEPARATOR, str_replace('chromedriver', 'chromedriver-'.$os, $binary), 2))[0]
: str_replace('chromedriver', 'chromedriver-'.$os, $binary);
}
30 changes: 30 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Orchestra\DuskUpdater\Tests;

use function Orchestra\DuskUpdater\chromedriver_binary_filename;
use PHPUnit\Framework\TestCase;

class HelpersTest extends TestCase
{
/**
* @dataProvider binaryFileDataProvider
*/
public function test_it_can_resolve_correct_filename($os, $given, $expected)
{
$this->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'];
}
}

0 comments on commit 0354868

Please sign in to comment.