Skip to content

Commit 9376c63

Browse files
committed
Update package test suite
1 parent 0f4ac7d commit 9376c63

File tree

5 files changed

+11
-40
lines changed

5 files changed

+11
-40
lines changed

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@
6969
"package": {
7070
"name": "httpwg/structured-field-tests",
7171
"version": "dev-main",
72-
"dist": {
73-
"url": "https://github.com/httpwg/structured-field-tests/archive/main.zip",
74-
"type": "zip"
75-
},
7672
"source": {
77-
"url": "git@github.com:httpwg/structured-field-tests.git",
73+
"url": "https://github.com/httpwg/structured-field-tests.git",
7874
"type": "git",
7975
"reference": "main"
8076
}

src/StructuredFieldTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function it_can_pass_http_wg_tests(TestUnit $test): void
2222
$this->expectException(SyntaxError::class);
2323
}
2424

25-
$structuredField = TestHeaderType::from($test->headerType)->newStructuredField(implode(',', $test->raw));
25+
$structuredField = TestFieldType::from($test->type)->newStructuredField(implode(',', $test->raw));
2626

2727
if (!$test->mustFail) {
2828
self::assertSame(implode(',', $test->canonical), $structuredField->toHttpValue());

src/TestHeaderType.php renamed to src/TestFieldType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Bakame\Http\StructuredFields;
66

7-
enum TestHeaderType: string
7+
enum TestFieldType: string
88
{
99
case Dictionary = 'dictionary';
1010
case List = 'list';

src/TestSuite.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use IteratorAggregate;
99
use JsonException;
1010
use RuntimeException;
11+
use function basename;
1112
use function fclose;
1213
use function fopen;
1314
use function is_resource;
@@ -19,15 +20,10 @@
1920
*/
2021
final class TestSuite implements IteratorAggregate
2122
{
22-
/** @var array<string, TestUnit> */
23-
private array $elements;
24-
25-
public function __construct(TestUnit ...$elements)
26-
{
27-
$this->elements = [];
28-
foreach ($elements as $element) {
29-
$this->add($element);
30-
}
23+
private function __construct(
24+
/** @var array<string, TestUnit> */
25+
private array $elements = []
26+
) {
3127
}
3228

3329
public function add(TestUnit $test): void
@@ -72,7 +68,7 @@ public static function fromPath(string $path, $context = null): self
7268
$records = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
7369
$suite = new self();
7470
foreach ($records as $offset => $record) {
75-
$record['name'] = '#'.($offset + 1).': '.$record['name'];
71+
$record['name'] = basename($path).' #'.($offset + 1).': '.$record['name'];
7672
$suite->add(TestUnit::fromDecoded($record));
7773
}
7874

src/TestUnit.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
namespace Bakame\Http\StructuredFields;
66

7-
use JsonException;
8-
use function json_decode;
9-
107
final class TestUnit
118
{
129
public function __construct(
1310
public readonly string $name,
14-
public readonly string $headerType,
11+
public readonly string $type,
1512
/** @var array<string> */
1613
public readonly array $raw,
1714
/** @var array<string> */
@@ -21,24 +18,6 @@ public function __construct(
2118
) {
2219
}
2320

24-
/**
25-
* @throws JsonException
26-
*/
27-
public static function fromJsonString(string $jsonTest): self
28-
{
29-
/** @var array{
30-
* name:string,
31-
* header_type: string,
32-
* raw: array<string>,
33-
* canonical?: array<string>,
34-
* must_fail?: bool,
35-
* can_fail?: bool
36-
* } $data */
37-
$data = json_decode($jsonTest, true, 512, JSON_THROW_ON_ERROR);
38-
39-
return self::fromDecoded($data);
40-
}
41-
4221
/**
4322
* @param array{
4423
* name:string,
@@ -51,7 +30,7 @@ public static function fromJsonString(string $jsonTest): self
5130
*/
5231
public static function fromDecoded(array $data): self
5332
{
54-
$data += ['must_fail' => false, 'can_fail' => false, 'canonical' => $data['raw']];
33+
$data += ['canonical' => $data['raw'], 'must_fail' => false, 'can_fail' => false];
5534

5635
return new self(
5736
$data['name'],

0 commit comments

Comments
 (0)