codenamephp / deploymentchecks.http
1.0.0
2024-01-17 08:54 UTC
Requires
- php: ^8.2
- codenamephp/deploymentchecks.base: *
- guzzlehttp/guzzle: ^7.5
- psr/http-client: ^1.0
- psr/http-message: 1 - 2
- symfony/css-selector: ^6.2 || ^7.0
- symfony/dom-crawler: ^6.2 || ^7.0
This package is auto-updated.
Last update: 2025-03-24 20:46:36 UTC
README
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, ...
Installation
Easiest way is via composer. Just run composer require codenamephp/deploymentchecks.http
in your cli which should install the latest version for you.
You should also explicitly install the codenamephp/deploymentchecks.base
package since you will end up using it directly in almost all cases.
Usage
Just create checks, pass them to a collection and run them:
use de\codenamephp\deploymentchecks\base\Check\Collection\SequentialCheckCollection; use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection; use de\codenamephp\deploymentchecks\http\HttpCheckResult; use de\codenamephp\deploymentchecks\http\RunTestsOnHttpResponse; use de\codenamephp\deploymentchecks\http\Test\CssSelectorExists; use de\codenamephp\deploymentchecks\http\Test\Result\HttpTestResult; use de\codenamephp\deploymentchecks\http\Test\StatusCode; use GuzzleHttp\Psr7\Request; $check = new SequentialCheckCollection(new RunTestsOnHttpResponse( new Request('GET', 'https://localhost/test.html'), 'Exists', new StatusCode(200), ), new RunTestsOnHttpResponse( new Request('GET','https://localhost/404.html'), 'Does not exist', new StatusCode(404), ), ); $result = $check->run(); exit($result instanceof WithExitCodeInterface ? $result->exitCode() : ($result->successful() ? DefaultExitCodes::SUCCESSFUL->value : DefaultExitCodes::ERROR->value));