Skip to content

Commit

Permalink
Merge branch 'main' into check-for-elements-on-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 31, 2023
2 parents 5fcadf7 + c0ba3f4 commit 0d5d82c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.3.6
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup NPM
uses: actions/setup-node@v3
with:
node-version: 16

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
tools: composer:v2

- name: Setup problem matchers
run: |
Expand Down
32 changes: 15 additions & 17 deletions src/Checks/Traits/ChecksUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use Illuminate\Support\Facades\Http;
use Spatie\Health\Exceptions\InvalidCheck;
use Vormkracht10\LaravelOK\Checks\Base\Check;
use Vormkracht10\LaravelOK\Checks\Base\Result;

Expand Down Expand Up @@ -72,32 +71,31 @@ public function failureMessage(string $failureMessage): self
public function run(): Result
{
if (is_null($this->url)) {
throw InvalidCheck::urlNotSet();
throw new Exception('URL not set');
}

try {
$request = Http::timeout($this->timeout)
->withHeaders($this->headers)
->retry($this->retryTimes)
->send($this->method, $this->url);

if (! $request->successful()) {
return $this->failedResult();
}
} catch (Exception) {
return $this->failedResult();
// try {
$request = Http::timeout($this->timeout)
->withHeaders($this->headers)
->retry($this->retryTimes)
->send($this->method, $this->url);

var_dump($request->successful());
if (! $request->successful()) {
// return $this->failedResult();
}
// } catch (Exception) {
// return $this->failedResult();
// }

return Result::new()
->ok()
->shortSummary('Reachable');
->ok();
}

protected function failedResult(): Result
{
return Result::new()
->failed()
->shortSummary('Unreachable')
->notificationMessage($this->failureMessage ?? "Pinging {$this->getName()} failed.");
->message($this->failureMessage ?? "Pinging {$this->getName()} failed.");
}
}
10 changes: 5 additions & 5 deletions src/Checks/Traits/RendersWebPage.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Spatie\Health\Checks\Checks;
namespace Vormkracht10\LaravelOK\Checks\Traits;

use Exception;
use Illuminate\Support\Facades\Http;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;
use Spatie\Health\Exceptions\InvalidCheck;
use Vormkracht10\LaravelOK\Checks\Base\Check;
use Vormkracht10\LaravelOK\Checks\Base\Result;
use Vormkracht10\LaravelOK\Exceptions\InvalidCheck;

class CheckUrl extends Check
class RendersWebPage extends Check
{
protected ?string $url = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/RunChecksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function runCheck(Check $check)
return $result;
}

protected function outputResultToConsole(Result $result, ?Exception $exception = null): void
protected function outputResultToConsole(Result $result, Exception $exception = null): void
{
match ($result->status) {
Status::OK => $this->output->write('<info>✓ Passed</info>', true),
Expand Down

0 comments on commit 0d5d82c

Please sign in to comment.