diff --git a/app/Commands/InstallBrowserCommand.php b/app/Commands/InstallBrowserCommand.php index 58a45bf..3b23e05 100644 --- a/app/Commands/InstallBrowserCommand.php +++ b/app/Commands/InstallBrowserCommand.php @@ -2,20 +2,13 @@ namespace App\Commands; -use App\Facades\GoogleForTesting; use App\GoogleDownloadable; use App\OperatingSystem; use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Str; + use function Laravel\Prompts\error; -use function Laravel\Prompts\outro; -use function Laravel\Prompts\search; use function Laravel\Prompts\spin; -use function Laravel\Prompts\warning; -use function Laravel\Prompts\info; -use function Termwind\render; class InstallBrowserCommand extends InstallCommand { @@ -36,7 +29,6 @@ class InstallBrowserCommand extends InstallCommand */ protected $description = 'Install Google Browser'; - protected array $platforms = [ 'linux' => 'linux64', 'mac-arm' => 'mac-arm64', diff --git a/app/Commands/InstallCommand.php b/app/Commands/InstallCommand.php index 60920d8..f2169c9 100644 --- a/app/Commands/InstallCommand.php +++ b/app/Commands/InstallCommand.php @@ -7,6 +7,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; + use function Laravel\Prompts\search; use function Laravel\Prompts\spin; use function Laravel\Prompts\warning; @@ -14,7 +15,7 @@ abstract class InstallCommand extends Command { - protected function version(): GoogleDownloadable|null + protected function version(): ?GoogleDownloadable { if ($this->option('latest')) { return GoogleForTesting::getLatestVersion(); @@ -40,7 +41,7 @@ protected function version(): GoogleDownloadable|null warning("There isn't an exact version [$version]"); $version = search( - label: "We found similar versions, please choose one", + label: 'We found similar versions, please choose one', options: fn () => $versions->mapWithKeys(fn ($d) => [$d->getVersion() => $d->getVersion()])->all(), placeholder: 'Choose your prefer version' ); @@ -48,7 +49,7 @@ protected function version(): GoogleDownloadable|null return GoogleForTesting::getVersion($version); } - protected function getBasePath(?string $path = null): string + protected function getBasePath(string $path = null): string { $folder = join_paths(getenv('HOME'), '.google-for-testing'); @@ -62,9 +63,9 @@ public function message(string $text, string $type = 'line'): void $color = match ($type) { 'success' => 'bg-green', 'warning' => 'bg-yellow', - 'error' => 'bg-red', - 'info' => 'bg-blue', - default => 'bg-gray-600', + 'error' => 'bg-red', + 'info' => 'bg-blue', + default => 'bg-gray-600', }; $type = str($type)->upper(); diff --git a/app/Commands/InstallDriverCommand.php b/app/Commands/InstallDriverCommand.php index 22c2c67..ce7a247 100644 --- a/app/Commands/InstallDriverCommand.php +++ b/app/Commands/InstallDriverCommand.php @@ -2,20 +2,13 @@ namespace App\Commands; -use App\Facades\GoogleForTesting; -use App\GoogleDownloadable; use App\OperatingSystem; use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Str; + use function Laravel\Prompts\error; use function Laravel\Prompts\outro; -use function Laravel\Prompts\search; use function Laravel\Prompts\spin; -use function Laravel\Prompts\warning; -use function Laravel\Prompts\info; -use function Termwind\render; class InstallDriverCommand extends InstallCommand { @@ -35,7 +28,6 @@ class InstallDriverCommand extends InstallCommand */ protected $description = 'Install Google Driver'; - protected array $platforms = [ 'linux' => 'linux64', 'mac-arm' => 'mac-arm64', diff --git a/app/Facades/GoogleForTesting.php b/app/Facades/GoogleForTesting.php index cd6e2b5..0ba1f2d 100644 --- a/app/Facades/GoogleForTesting.php +++ b/app/Facades/GoogleForTesting.php @@ -5,7 +5,6 @@ use App\GoogleDownloadable; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Facade; -use Illuminate\Support\Facades\Http; /** * @method static null|GoogleDownloadable getLatestVersion() Get the latest version of Google Chrome Browser and Google Chrome Driver diff --git a/app/GoogleForTesting.php b/app/GoogleForTesting.php index edb1878..91ff6ef 100644 --- a/app/GoogleForTesting.php +++ b/app/GoogleForTesting.php @@ -2,9 +2,9 @@ namespace App; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; -use Illuminate\Support\Collection; class GoogleForTesting { @@ -32,7 +32,7 @@ public function getVersion(string $version): ?GoogleDownloadable $response = Http::get(static::$downloads); $exact = collect($response->json('versions')) - ->first(fn(array $item) => $item['version'] == $version); + ->first(fn (array $item) => $item['version'] == $version); if (empty($exact)) { return null; diff --git a/app/helpers.php b/app/helpers.php index 397e431..56fbb3c 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -16,7 +16,7 @@ function join_paths(string ...$paths): string array_map(fn (string $p) => trim($p, DIRECTORY_SEPARATOR), $paths) ); - return join(DIRECTORY_SEPARATOR, [rtrim($first, DIRECTORY_SEPARATOR), ...$paths]); + return implode(DIRECTORY_SEPARATOR, [rtrim($first, DIRECTORY_SEPARATOR), ...$paths]); } } @@ -61,9 +61,8 @@ function download(string $url, string $file, bool $force = false): void * This function will attempt to unzip the given zip file name into the given location, but if the location * is not provided, we'll use the file directory. * - * @param string $filename The file name of the ZIP file - * @param ?string $to The location where to extract the content - * @return void + * @param string $filename The file name of the ZIP file + * @param ?string $to The location where to extract the content */ function unzip(string $filename, string $to = null): void { diff --git a/tests/Feature/InstallBrowserCommandTest.php b/tests/Feature/InstallBrowserCommandTest.php index fb9ca4d..859d486 100644 --- a/tests/Feature/InstallBrowserCommandTest.php +++ b/tests/Feature/InstallBrowserCommandTest.php @@ -4,6 +4,7 @@ use App\GoogleDownloadable; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; + use function Pest\Laravel\artisan; it('download the latest browser version', function () { @@ -72,7 +73,7 @@ ->doesntExpectOutputToContain("There' no versions available for [200.0.0.0]") ->expectsOutputToContain('Downloading Google Chrome Browser [200.0.0.0]') ->expectsOutputToContain('Google Chrome Browser [200.0.0.0] downloaded') - ->expectsOutputToContain("Google Chrome Browser unzip it on [/some/dir/to/download]") + ->expectsOutputToContain('Google Chrome Browser unzip it on [/some/dir/to/download]') ->assertSuccessful(); }); diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.php index b6957d3..9443fac 100644 --- a/tests/Unit/HelpersTest.php +++ b/tests/Unit/HelpersTest.php @@ -6,16 +6,16 @@ dataset('paths', fn () => [ 'simple path' => [ 'paths' => ['/this', 'is', 'a', 'path/'], - 'result' => '/this/is/a/path' + 'result' => '/this/is/a/path', ], 'weird path' => [ 'paths' => ['/just/another/', '/path/to/', '/join//'], - 'result' => '/just/another/path/to/join' + 'result' => '/just/another/path/to/join', ], 'strange path' => [ 'paths' => ['what', '//is//this/', '//path//'], - 'result' => 'what/is//this/path' - ] + 'result' => 'what/is//this/path', + ], ]); afterAll(fn () => File::delete(join_paths(__DIR__, '..', 'files', 'file.txt'))); @@ -26,26 +26,26 @@ })->with('paths'); it('download a file', function () { - Http::fake(); + Http::fake(); - $fileMock = File::partialMock(); + $fileMock = File::partialMock(); - $fileMock - ->shouldReceive('exists') - ->andReturn(false, true); + $fileMock + ->shouldReceive('exists') + ->andReturn(false, true); - $fileMock - ->shouldReceive('delete') - ->andReturn(false); + $fileMock + ->shouldReceive('delete') + ->andReturn(false); - $fileMock - ->expects('append') - ->andReturn(); + $fileMock + ->expects('append') + ->andReturn(); - expect(fn () => download('https://fake-download.com', '/path/to/a/file.zip')) - ->not->toThrow(\Exception::class) - ->and(File::exists('/path/to/a/file.zip')) - ->toBeTrue(); + expect(fn () => download('https://fake-download.com', '/path/to/a/file.zip')) + ->not->toThrow(\Exception::class) + ->and(File::exists('/path/to/a/file.zip')) + ->toBeTrue(); }); it('try to download a file that already exists', function () { @@ -61,7 +61,6 @@ ->toThrow(\Exception::class); }); - it('delete a pre-existing file to download it again', function () { Http::fake(); @@ -95,6 +94,3 @@ ->and(File::exists($file)) ->toBeTrue(); }); - - -