Skip to content

Commit 72589f8

Browse files
Http checks now use names
1 parent f9cfd19 commit 72589f8

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

packages/http/src/Check/HttpCheck.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
namespace de\codenamephp\deploymentchecks\http\Check;
1919

2020
use de\codenamephp\deploymentchecks\base\Check\CheckInterface;
21-
use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection;
2221
use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface;
2322
use de\codenamephp\deploymentchecks\base\Check\WithNameInterface;
23+
use de\codenamephp\deploymentchecks\http\Check\Result\HttpCheckResult;
2424
use de\codenamephp\deploymentchecks\http\Check\Test\TestInterface;
2525
use GuzzleHttp\Client;
2626
use Psr\Http\Message\RequestInterface;
@@ -47,6 +47,6 @@ public function name() : string {
4747
public function run() : ResultInterface {
4848
$client = new Client();
4949
$response = $client->send($this->request);
50-
return new ResultCollection(...array_map(fn(TestInterface $test) => $test->test($response), $this->tests));
50+
return new HttpCheckResult($this->name(), ...array_map(fn(TestInterface $test) => $test->test($response), $this->tests));
5151
}
5252
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deploymentchecks\http\Check\Result;
19+
20+
use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection;
21+
use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollectionInterface;
22+
use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface;
23+
use de\codenamephp\deploymentchecks\base\Check\Result\WithNameInterface;
24+
25+
final readonly class HttpCheckResult implements ResultCollectionInterface, WithNameInterface {
26+
27+
public ResultCollectionInterface $testResults;
28+
29+
public function __construct(public string $name, ResultInterface ...$testResults) {
30+
$this->testResults = new ResultCollection(...$testResults);
31+
}
32+
33+
public function add(ResultInterface $result) : self {
34+
$this->testResults->add($result);
35+
return $this;
36+
}
37+
38+
public function successful() : bool {
39+
return $this->testResults->successful();
40+
}
41+
42+
public function name() : string {
43+
return $this->name;
44+
}
45+
}

packages/test/src/test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use de\codenamephp\deploymentchecks\http\Check\HttpCheck;
2121
use de\codenamephp\deploymentchecks\http\Check\Test\StatusCode;
2222
use GuzzleHttp\Psr7\Request;
23-
use Spatie\Fork\Fork;
2423

2524
require_once __DIR__ . '/../vendor/autoload.php';
2625

0 commit comments

Comments
 (0)