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, ...
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.
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));