|
8 | 8 |  |
9 | 9 |  |
10 | 10 |
|
| 11 | +This package provides simple checks for http services. It can check if a service is reachable and if it returns a specific status code, response body, ... |
| 12 | + |
11 | 13 | ## Installation |
12 | 14 |
|
13 | 15 | Easiest way is via composer. Just run `composer require codenamephp/deploymentchecks.http` in your cli which should install the latest version for you. |
14 | 16 |
|
15 | | -## Usage |
| 17 | +You should also explicitly install the `codenamephp/deploymentchecks.base` package since you will end up using it directly in almost all cases. |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Just create checks, pass them to a collection and run them: |
| 22 | + |
| 23 | +```php |
| 24 | +use de\codenamephp\deploymentchecks\base\Check\Collection\SequentialCheckCollection; |
| 25 | +use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection; |
| 26 | +use de\codenamephp\deploymentchecks\http\HttpCheckResult; |
| 27 | +use de\codenamephp\deploymentchecks\http\RunTestsOnHttpResponse; |
| 28 | +use de\codenamephp\deploymentchecks\http\Test\CssSelectorExists; |
| 29 | +use de\codenamephp\deploymentchecks\http\Test\Result\HttpTestResult; |
| 30 | +use de\codenamephp\deploymentchecks\http\Test\StatusCode; |
| 31 | +use GuzzleHttp\Psr7\Request; |
| 32 | + |
| 33 | +$check = new SequentialCheckCollection(new RunTestsOnHttpResponse( |
| 34 | + new Request('GET', 'https://localhost/test.html'), |
| 35 | + 'Exists', |
| 36 | + new StatusCode(200), |
| 37 | +), |
| 38 | + new RunTestsOnHttpResponse( |
| 39 | + new Request('GET','https://localhost/404.html'), |
| 40 | + 'Does not exist', |
| 41 | + new StatusCode(404), |
| 42 | + ), |
| 43 | +); |
| 44 | + |
| 45 | +$result = $check->run(); |
| 46 | + |
| 47 | +exit($result instanceof WithExitCodeInterface ? $result->exitCode() : ($result->successful() ? DefaultExitCodes::SUCCESSFUL->value : DefaultExitCodes::ERROR->value)); |
| 48 | +``` |
0 commit comments