Skip to content

Commit 99b05a7

Browse files
committed
Improve Loading test files
1 parent f5358ad commit 99b05a7

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/TestRecord.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
namespace Bakame\Http\StructuredFields;
66

7+
/**
8+
* @phpstan-type RecordData array{
9+
* name:string,
10+
* header_type:string,
11+
* raw:array<string>,
12+
* canonical?: array<string>,
13+
* must_fail?: bool,
14+
* can_fail?: bool
15+
* }
16+
*/
717
final class TestRecord
818
{
919
private function __construct(
@@ -19,14 +29,7 @@ private function __construct(
1929
}
2030

2131
/**
22-
* @param array{
23-
* name:string,
24-
* header_type:string,
25-
* raw:array<string>,
26-
* canonical?: array<string>,
27-
* must_fail?: bool,
28-
* can_fail?: bool
29-
* } $data
32+
* @param RecordData $data
3033
*/
3134
public static function fromDecoded(array $data): self
3235
{

src/TestRecordCollection.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
/**
1919
* @implements IteratorAggregate<string, TestRecord>
20+
* @phpstan-import-type RecordData from TestRecord
2021
*/
2122
final class TestRecordCollection implements IteratorAggregate
2223
{
@@ -39,7 +40,7 @@ public function add(TestRecord $test): void
3940
/**
4041
* @param resource|null $context
4142
*
42-
* @throws JsonException
43+
* @throws JsonException|RuntimeException
4344
*/
4445
public static function fromPath(string $path, $context = null): self
4546
{
@@ -58,14 +59,7 @@ public static function fromPath(string $path, $context = null): self
5859
$content = stream_get_contents($resource);
5960
fclose($resource);
6061

61-
/** @var array<array{
62-
* name: string,
63-
* header_type: string,
64-
* raw: array<string>,
65-
* canonical?: array<string>,
66-
* must_fail?: bool,
67-
* can_fail?: bool
68-
* }> $records */
62+
/** @var array<RecordData> $records */
6963
$records = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
7064
$suite = new self();
7165
foreach ($records as $offset => $record) {

0 commit comments

Comments
 (0)