Skip to content

Commit 2fd4dd1

Browse files
committed
Improve Token test suite
1 parent 64aa702 commit 2fd4dd1

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
1010

1111
### Fixed
1212

13-
- `Parser` no longer returns the `Item` instance
14-
- `Parser` improve internal Date generation
15-
- `Value` improve float serialization
13+
- `Parser` no longer instantiate an `Item` object
14+
- `Parser` internal Date generation simplified
15+
- `Value` float serialization simplified
1616
- `OuterList::fromHttpValue`, `InnerList::fromHttpValue`, `Dictionnary::fromHttpValue` rewritten to improve decoupling from `Parser`
17+
- Adding missing interoperability test for the `Token` type
1718

1819
### Deprecated
1920

src/InnerList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public static function fromAssociative(iterable $value, iterable $parameters): s
9292
public static function fromPair(array $pair): self
9393
{
9494
return match (true) {
95-
!array_is_list($pair) => throw new SyntaxError('The pair must be represented by an array as a list.'), /* @phpstan-ignore-line */
96-
2 !== count($pair) => throw new SyntaxError('The pair first member must be the member list and the second member the inner list parameters.'), /* @phpstan-ignore-line */
95+
!array_is_list($pair) => throw new SyntaxError('The pair must be represented by an array as a list.'), // @phpstan-ignore-line
96+
2 !== count($pair) => throw new SyntaxError('The pair first member must be the member list and the second member the inner list parameters.'), // @phpstan-ignore-line
9797
default => new self($pair[0], !$pair[1] instanceof Parameters ? Parameters::fromPairs($pair[1]) : $pair[1]),
9898
};
9999
}

src/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public static function fromAssociative(DateTimeInterface|ByteSequence|Token|stri
7979
public static function fromPair(array $pair): self
8080
{
8181
return match (true) {
82-
!array_is_list($pair) => throw new SyntaxError('The pair must be represented by an array as a list.'), /* @phpstan-ignore-line */
83-
2 !== count($pair) => throw new SyntaxError('The pair first member is the item value; its second member is the item parameters.'), /* @phpstan-ignore-line */
82+
!array_is_list($pair) => throw new SyntaxError('The pair must be represented by an array as a list.'), // @phpstan-ignore-line
83+
2 !== count($pair) => throw new SyntaxError('The pair first member is the item value; its second member is the item parameters.'), // @phpstan-ignore-line
8484
default => new self(new Value($pair[0]), $pair[1] instanceof Parameters ? $pair[1] : Parameters::fromPairs($pair[1])),
8585
};
8686
}

src/ParametersTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Bakame\Http\StructuredFields;
66

77
use LogicException;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\Attributes\Test;
910

1011
final class ParametersTest extends StructuredFieldTestCase
@@ -63,11 +64,21 @@ public function it_fails_to_instantiate_with_an_item_containing_already_paramete
6364
}
6465

6566
#[Test]
66-
public function it_fails_to_instantiate_with_an_parameter_key_as_int(): void
67+
#[DataProvider('invalidMapKeyProvider')]
68+
public function it_fails_to_instantiate_with_a_parameter_and_an_invalid_key(string|int $key): void
6769
{
6870
$this->expectException(SyntaxError::class);
6971

70-
Parameters::fromAssociative([1 => Item::true()]); // @phpstan-ignore-line
72+
Parameters::fromAssociative([$key => Item::true()]); // @phpstan-ignore-line
73+
}
74+
75+
/**
76+
* @return iterable<string,array{key:string|int}>
77+
*/
78+
public static function invalidMapKeyProvider(): iterable
79+
{
80+
yield 'key is an integer' => ['key' => 42];
81+
yield 'key start with an integer' => ['key' => '1b'];
7182
}
7283

7384
#[Test]

src/TokenTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
use PHPUnit\Framework\Attributes\DataProvider;
88
use PHPUnit\Framework\Attributes\Test;
9-
use PHPUnit\Framework\TestCase;
109

11-
final class TokenTest extends TestCase
10+
final class TokenTest extends StructuredFieldTestCase
1211
{
12+
/** @var array<string> */
13+
protected static array $httpWgTestFilenames = [
14+
'token.json',
15+
'token-generated.json',
16+
];
17+
1318
#[Test]
1419
#[DataProvider('invalidTokenString')]
1520
public function it_will_fail_on_invalid_token_string(string $httpValue): void

src/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function fromValue(ValueAccess|Token|ByteSequence|DateTimeInterfac
3737
public static function tryFromValue(mixed $value): self|null
3838
{
3939
try {
40-
return self::fromValue($value); /* @phpstan-ignore-line */
40+
return self::fromValue($value); // @phpstan-ignore-line
4141
} catch (Throwable) {
4242
return null;
4343
}

src/TypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function it_can_tell_the_item_type_from_a_value_instance(): void
3535
#[DataProvider('itemTypeProvider')]
3636
public function it_can_tell_the_item_type(mixed $value, Type $expectedType): void
3737
{
38-
self::assertTrue($expectedType->equals(Type::fromValue($value))); /* @phpstan-ignore-line */
38+
self::assertTrue($expectedType->equals(Type::fromValue($value))); // @phpstan-ignore-line
3939
self::assertTrue($expectedType->equals(Type::tryFromValue($value)));
4040
}
4141

0 commit comments

Comments
 (0)