Skip to content

Commit

Permalink
chore: fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
asciito committed Oct 20, 2023
1 parent de8e84f commit 60f1a53
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 55 deletions.
10 changes: 1 addition & 9 deletions app/Commands/InstallBrowserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -36,7 +29,6 @@ class InstallBrowserCommand extends InstallCommand
*/
protected $description = 'Install Google Browser';


protected array $platforms = [
'linux' => 'linux64',
'mac-arm' => 'mac-arm64',
Expand Down
13 changes: 7 additions & 6 deletions app/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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;
use function Termwind\render;

abstract class InstallCommand extends Command
{
protected function version(): GoogleDownloadable|null
protected function version(): ?GoogleDownloadable
{
if ($this->option('latest')) {
return GoogleForTesting::getLatestVersion();
Expand All @@ -40,15 +41,15 @@ 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'
);

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');

Expand All @@ -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();
Expand Down
10 changes: 1 addition & 9 deletions app/Commands/InstallDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -35,7 +28,6 @@ class InstallDriverCommand extends InstallCommand
*/
protected $description = 'Install Google Driver';


protected array $platforms = [
'linux' => 'linux64',
'mac-arm' => 'mac-arm64',
Expand Down
1 change: 0 additions & 1 deletion app/Facades/GoogleForTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/GoogleForTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/InstallBrowserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});

Expand Down
42 changes: 19 additions & 23 deletions tests/Unit/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand All @@ -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 () {
Expand All @@ -61,7 +61,6 @@
->toThrow(\Exception::class);
});


it('delete a pre-existing file to download it again', function () {
Http::fake();

Expand Down Expand Up @@ -95,6 +94,3 @@
->and(File::exists($file))
->toBeTrue();
});



0 comments on commit 60f1a53

Please sign in to comment.