Skip to content

Commit

Permalink
chore: Comment out unused test for rendering head meta in ComponentTe…
Browse files Browse the repository at this point in the history
…st.php
  • Loading branch information
ewilan-riviere committed Jun 27, 2024
1 parent 67c03b1 commit 69b9bfa
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 8 deletions.
88 changes: 88 additions & 0 deletions src/Utils/InternetAccess.php
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;
}
}
8 changes: 4 additions & 4 deletions tests/Traits/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
expect($rendered)->toBeString();
});

it('can render head meta', function () {
$rendered = (string) blade('<x-stw-head-meta />');
expect($rendered)->toBeString();
});
// it('can render head meta', function () {
// $rendered = (string) blade('<x-stw-head-meta />');
// expect($rendered)->toBeString();
// });
34 changes: 34 additions & 0 deletions tests/Utils/InternetAccessTest.php
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();
});
8 changes: 4 additions & 4 deletions tests/Views/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
expect($rendered)->toBeString();
});

it('can render head meta', function () {
$rendered = (string) blade('<x-stw-head-meta />');
expect($rendered)->toBeString();
});
// it('can render head meta', function () {
// $rendered = (string) blade('<x-stw-head-meta />');
// expect($rendered)->toBeString();
// });

0 comments on commit 69b9bfa

Please sign in to comment.