Skip to content

Commit

Permalink
Add extensive tests for Header::normalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla committed Oct 5, 2021
1 parent f7d9989 commit ad75894
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions tests/HeaderTest.php
Expand Up @@ -63,9 +63,67 @@ public function testParseParams($header, $result): void
self::assertSame($result, Psr7\Header::parse($header));
}

public function testParsesArrayHeaders(): void
public function normalizeProvider(): array
{
$header = ['a, b', 'c', 'd, e'];
self::assertSame(['a', 'b', 'c', 'd', 'e'], Psr7\Header::normalize($header));
return [
[
['a, b', 'c', 'd, e'],
['a', 'b', 'c', 'd', 'e'],
],
// Example 'accept-encoding'
[
'gzip, br',
['gzip', 'br'],
],
// https://httpwg.org/specs/rfc7231.html#rfc.section.5.3.2
[
'text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c',
['text/plain; q=0.5', 'text/html', 'text/x-dvi; q=0.8', 'text/x-c'],
],
// Example 'If-None-Match' with comma within an ETag
[
'"foo", "foo,bar", "bar"',
['"foo"', '"foo,bar"', '"bar"'],
],
// https://httpwg.org/specs/rfc7234.html#cache.control.extensions
[
'private, community="UCI"',
['private', 'community="UCI"'],
],
// The Cache-Control example with a comma within a community
[
'private, community="Guzzle,Psr7"',
['private', 'community="Guzzle,Psr7"'],
],
// The Cache-Control example with an escaped space (quoted-pair) within a community
[
'private, community="Guzzle\\ Psr7"',
['private', 'community="Guzzle\\ Psr7"'],
],
// The Cache-Control example with an escaped quote (quoted-pair) space within a community
[
'private, community="Guzzle\\"Psr7"',
['private', 'community="Guzzle\\"Psr7"'],
],
// https://httpwg.org/specs/rfc7230.html#rfc.section.7
[
'foo ,bar,',
['foo', 'bar'],
],
// https://httpwg.org/specs/rfc7230.html#rfc.section.7
[
'foo , ,bar,charlie ',
['foo', 'bar', 'charlie'],
]
];
}

/**
* @dataProvider normalizeProvider
*/
public function testNormalize($header, $result): void
{
self::assertSame($result, Psr7\Header::normalize([$header]));
self::assertSame($result, Psr7\Header::normalize($header));
}
}

0 comments on commit ad75894

Please sign in to comment.