Skip to content

Commit

Permalink
refactor: add unzip function
Browse files Browse the repository at this point in the history
This commit also catch any exception and display and error message.
  • Loading branch information
asciito committed Oct 19, 2023
1 parent 7da59e5 commit d87be4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
30 changes: 26 additions & 4 deletions app/Commands/InstallBrowserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\OperatingSystem;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
use function Laravel\Prompts\error;
Expand Down Expand Up @@ -60,10 +61,31 @@ public function handle(): int

$version = $downloadable->getVersion();

spin(
callback: fn () => download($downloadable->getChromeBrowserURL($this->platforms[$os]), $this->filename($os)),
message: "Downloading Google Chrome Browser [$version]"
);
$filename = $this->filename($os);

try {
$result = true;

spin(
callback: fn () => download($downloadable->getChromeBrowserURL($this->platforms[$os]), $filename),
message: "Downloading Google Chrome Browser [$version]"
);

spin(
callback: fn () => unzip($filename),
message: 'Unzipping Google Chrome Browser',
);
} catch (\Exception $e) {
Log::error($e->getMessage());

$result = false;
}

if (! $result) {
error("Unable to download/install Google Chrome Browser [$version]");

return self::FAILURE;
}

outro("Google Chrome Browser [$version] downloaded");

Expand Down
10 changes: 9 additions & 1 deletion tests/Feature/InstallBrowserCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Support\Facades\File;
use Symfony\Component\Finder\Finder;
use function Pest\Laravel\artisan;

it('download the latest browser version', function () {
Expand All @@ -9,7 +10,14 @@
->expectsOutputToContain('downloaded')
->assertSuccessful();

expect(File::exists(join_paths(env('HOME'), '.google-for-testing', 'chrome-mac-arm64.zip')))
$finder = new Finder;

$finder
->directories()
->in(join_paths(env('HOME'), '.google-for-testing'))
->name('chrome*');

expect($finder->hasResults())
->toBeTrue();
});

Expand Down

0 comments on commit d87be4c

Please sign in to comment.