diff --git a/app/Commands/InstallBrowserCommand.php b/app/Commands/InstallBrowserCommand.php index b788fb1..7be4836 100644 --- a/app/Commands/InstallBrowserCommand.php +++ b/app/Commands/InstallBrowserCommand.php @@ -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; @@ -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"); diff --git a/tests/Feature/InstallBrowserCommandTest.php b/tests/Feature/InstallBrowserCommandTest.php index 5e5af89..8dab1cf 100644 --- a/tests/Feature/InstallBrowserCommandTest.php +++ b/tests/Feature/InstallBrowserCommandTest.php @@ -1,6 +1,7 @@ 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(); });