Skip to content

Commit

Permalink
[release:major] - firstpackage major publish
Browse files Browse the repository at this point in the history
- update documentation in README.md
- refactor using-poo.php example
- fix typo in code
  • Loading branch information
gritzkoo committed Jun 25, 2022
1 parent 3fddc75 commit 6fdf73c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ___

## $checker->liveness()

Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that allows you to check if your application is *OK* without checking any kind of integration.
Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that allows you to check if your application is _OK_ without checking any kind of integration.

```json
{
Expand All @@ -91,7 +91,7 @@ Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that
"version": "v1.0.0",
// the main status checks, will return true when all integrations does not fail
"status": true,
//
// ISO 8601 date
"date": "2022-06-25T11:52:56-03:00",
"duration": 0.08681011199951172,
"integrations": [
Expand All @@ -111,6 +111,7 @@ Will return an **_ARRAY_** that you can convert to **_JSON_** as below and that
```sh
composer require gritzkoo/php-health-checker
```

## Create a HTTP inteface to expose probs

Once you create an instance of `Gritzkoo\HealthChecker\HealthChecker` you should create 2 routes in your application to expose `liveness` and `readiness` actions like:
Expand Down Expand Up @@ -144,11 +145,12 @@ class HealthCheckController extends Controller
return $this->checker->readiness()
}
}
```
```

___

>route file `routes/web.php`
>route file `routes/web.php`
```php
<?php

Expand Down
6 changes: 5 additions & 1 deletion docs/examples/using-poo.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Services\Healthcheck;
namespace App\Services;

use App\Api\YourIntegrationA;
use App\Api\YourIntegrationb;
Expand Down Expand Up @@ -30,10 +30,14 @@ public function __construct(
'integrations' => [
[
'name' => 'YourIntegrationA',
// is just a closure you write to test something and return
// an instance of \Gritzkoo\HealthChecker\Check
'handle' => $api1->test
],
[
'name' => 'YourIntegrationB',
// is just a closure you write to test something and return
// an instance of \Gritzkoo\HealthChecker\Check
'handle' => $api2->test
],
]
Expand Down
20 changes: 19 additions & 1 deletion src/HealthChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ public function liveness()
];
}
/**
* Undocumented function
* Readiness will return a full set of informations about the
* integrations list you pass to create a instance of \Gritzkoo\HealthChecker\HealthChecker
* with aditional informations like:
* {
* "name": "My application name",
* "version": "v1.0.0",
* "status": true,
* "date": "2022-06-25T11:52:56-03:00",
* "duration": 0.08681011199951172,
* "integrations": [
* {
* "name": "github status check",
* "status": true,
* "response_time": 0.08406686782836914,
* "url": "https://github.com/status",
* "error": null
* }
* ]
* }
*
* @return array
*/
Expand Down
41 changes: 39 additions & 2 deletions tests/Providers/HealthCheckerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function () {
];
}
],
// testing integrations
// testing integrations ===============================================================
'should run readiness with a integration' => [
function () {
$conf = $this->defaultConfig;
Expand All @@ -77,6 +77,43 @@ function () {
];
}
],
'should run readiness and fail because the second integration fail' => [
function () {
$conf = $this->defaultConfig;
$conf['integrations'] = [
[
'name' => 'test 1',
'handle' => function () {
return new Check();
}
],
[
'name' => 'test 2',
'handle' => function () {
return new Check(['error' => 'some error']);
}
]
];
$exp = $this->readinessContract;
$exp['status'] = false;
$exp['integrations'] = [
[
'name' => 'test 1',
'status' => true,
],
[
'name' => 'test 2',
'status' => false,
'error' => 'some error'
]
];
return [
'method' => Constants::READINESS,
'config' => $conf,
'expected' => $exp
];
}
],
'should run readiness with a integration and validate return type' => [
function () {
$conf = $this->defaultConfig;
Expand Down Expand Up @@ -154,7 +191,7 @@ function () {
];
}
],
// error section ======================================================================
// throw section ======================================================================
'should throw error because construct is not an array' => [
function () {
return [
Expand Down

0 comments on commit 6fdf73c

Please sign in to comment.