Skip to content

Commit 3cd6d40

Browse files
committed
Improve Test suite
1 parent 8a690f7 commit 3cd6d40

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

src/Parameters.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ public function mergePairs(Parameters|iterable ...$others): self
404404
*/
405405
public function sanitize(): self
406406
{
407-
$this->members = array_map(fn (Item $item): Item => $item->parameters->clear(), $this->members);
407+
$this->members = array_map(function (Item $item): Item {
408+
$item->parameters->clear();
409+
410+
return $item;
411+
}, $this->members);
408412

409413
return $this;
410414
}

src/StructuredFieldTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ abstract class StructuredFieldTest extends TestCase
1616
* @dataProvider httpWgDataProvider
1717
* @test
1818
*/
19-
public function it_can_pass_http_wg_tests(TestUnit $test): void
19+
public function it_can_pass_http_wg_tests(TestRecord $test): void
2020
{
2121
if ($test->mustFail) {
2222
$this->expectException(SyntaxError::class);
2323
}
2424

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

2727
if (!$test->mustFail) {
2828
self::assertSame(implode(',', $test->canonical), $structuredField->toHttpValue());
@@ -31,12 +31,12 @@ public function it_can_pass_http_wg_tests(TestUnit $test): void
3131

3232
/**
3333
* @throws JsonException
34-
* @return iterable<string, array<TestUnit>>
34+
* @return iterable<string, array<TestRecord>>
3535
*/
3636
public function httpWgDataProvider(): iterable
3737
{
3838
foreach ($this->paths as $path) {
39-
foreach (TestSuite::fromPath($path) as $test) {
39+
foreach (TestRecordCollection::fromPath($path) as $test) {
4040
yield $test->name => [$test];
4141
}
4242
}

src/TestFieldType.php renamed to src/TestDataType.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 TestFieldType: string
7+
enum TestDataType: string
88
{
99
case Dictionary = 'dictionary';
1010
case List = 'list';

src/TestUnit.php renamed to src/TestRecord.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-
final class TestUnit
7+
final class TestRecord
88
{
99
public function __construct(
1010
public readonly string $name,

src/TestSuite.php renamed to src/TestRecordCollection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
use function stream_get_contents;
1717

1818
/**
19-
* @implements IteratorAggregate<string, TestUnit>
19+
* @implements IteratorAggregate<string, TestRecord>
2020
*/
21-
final class TestSuite implements IteratorAggregate
21+
final class TestRecordCollection implements IteratorAggregate
2222
{
2323
private function __construct(
24-
/** @var array<string, TestUnit> */
24+
/** @var array<string, TestRecord> */
2525
private array $elements = []
2626
) {
2727
}
2828

29-
public function add(TestUnit $test): void
29+
public function add(TestRecord $test): void
3030
{
3131
if (isset($this->elements[$test->name])) {
3232
throw new RuntimeException('Already existing test name `'.$test->name.'`');
@@ -69,14 +69,14 @@ public static function fromPath(string $path, $context = null): self
6969
$suite = new self();
7070
foreach ($records as $offset => $record) {
7171
$record['name'] = basename($path).' #'.($offset + 1).': '.$record['name'];
72-
$suite->add(TestUnit::fromDecoded($record));
72+
$suite->add(TestRecord::fromDecoded($record));
7373
}
7474

7575
return $suite;
7676
}
7777

7878
/**
79-
* @return Iterator<string, TestUnit>
79+
* @return Iterator<string, TestRecord>
8080
*/
8181
public function getIterator(): Iterator
8282
{

0 commit comments

Comments
 (0)