generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Comment out unused test for rendering head meta in ComponentTe…
…st.php
- Loading branch information
1 parent
67c03b1
commit 69b9bfa
Showing
4 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Kiwilan\Steward\Utils; | ||
|
||
class InternetAccess | ||
{ | ||
protected function __construct( | ||
protected string $provider = 'www.google.com', | ||
protected bool $force_https = false, | ||
protected ?string $url = null, | ||
protected ?string $status = null, | ||
protected ?int $status_code = null, | ||
protected bool $is_available = false | ||
) { | ||
} | ||
|
||
/** | ||
* Check if the internet is available. | ||
* | ||
* @param string $provider The provider to check, default is Google. You can use 'www.google.com' or 'whatismyipaddress.com' | ||
* @param bool $force_https Force the connection to use HTTPS | ||
*/ | ||
public static function check(string $provider = 'www.google.com', bool $force_https = false): self | ||
{ | ||
$self = new self($provider, $force_https); | ||
|
||
if (str_contains($self->provider, 'http://')) { | ||
$self->provider = str_replace('http://', '', $self->provider); | ||
} | ||
|
||
if (str_contains($self->provider, 'https://')) { | ||
$self->provider = str_replace('https://', '', $self->provider); | ||
} | ||
|
||
if ($force_https) { | ||
$self->url = "https://{$self->provider}"; | ||
} else { | ||
$self->url = "http://{$self->provider}"; | ||
} | ||
|
||
try { | ||
[$status] = get_headers($self->url); | ||
$self->status = $status; | ||
$self->status_code = (int) explode(' ', $status)[1]; | ||
} catch (\Throwable $th) { | ||
return $self; | ||
} | ||
|
||
$self->is_available = true; | ||
|
||
return $self; | ||
} | ||
|
||
public function isAvailable(): bool | ||
{ | ||
return $this->is_available; | ||
} | ||
|
||
public function isOk(): bool | ||
{ | ||
return $this->status_code === 200; | ||
} | ||
|
||
public function getStatus(): ?string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function getStatusCode(): ?int | ||
{ | ||
return $this->status_code; | ||
} | ||
|
||
public function getUrl(): ?string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function getProvider(): string | ||
{ | ||
return $this->provider; | ||
} | ||
|
||
public function getForceHttps(): bool | ||
{ | ||
return $this->force_https; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Kiwilan\Steward\Utils\InternetAccess; | ||
|
||
it('can check if internet is available', function () { | ||
$check = InternetAccess::check(); | ||
|
||
expect($check->isAvailable())->toBeTrue(); | ||
expect($check->isOk())->toBeTrue(); | ||
}); | ||
|
||
it('can check with https', function () { | ||
$check = InternetAccess::check(force_https: true); | ||
|
||
expect($check->isAvailable())->toBeTrue(); | ||
}); | ||
|
||
it('can check with http prefix', function () { | ||
$check = InternetAccess::check('http://www.google.com'); | ||
|
||
expect($check->isAvailable())->toBeTrue(); | ||
}); | ||
|
||
it('can check with ewilan-riviere.com', function () { | ||
$check = InternetAccess::check('ewilan-riviere.com'); | ||
|
||
expect($check->isAvailable())->toBeTrue(); | ||
}); | ||
|
||
it('can check with abcdefghikl.com', function () { | ||
$check = InternetAccess::check('abcdefghikl.com'); | ||
|
||
expect($check->isAvailable())->toBeFalse(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters