Skip to content

Commit

Permalink
Move parsing test to QueryString test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 14, 2023
1 parent a7a0ebb commit c1cf91e
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions Components/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use Stringable;
use function is_array;
use function json_encode;

/**
Expand Down Expand Up @@ -86,44 +85,6 @@ public function testGetUriComponent(): void
self::assertSame('?foo=bar', Query::new('foo=bar')->getUriComponent());
}

/**
* @dataProvider queryProvider
*/
public function testStringRepresentationComponent(string|array|Query $input, string $expected): void
{
$query = is_array($input) ? Query::fromPairs($input) : Query::new($input);

self::assertSame($expected, $query->toString());
}

public static function queryProvider(): array
{
$unreserved = 'a-zA-Z0-9.-_~!$&\'()*,;=:@';

return [
'bug fix issue 84' => ['fào=?%25bar&q=v%61lue', 'f%C3%A0o=?%25bar&q=value'],
'string' => ['kingkong=toto', 'kingkong=toto'],
'query object' => [Query::new('kingkong=toto'), 'kingkong=toto'],
'empty string' => ['', ''],
'empty array' => [[], ''],
'non empty array' => [[['', null]], ''],
'contains a reserved word #' => ['foo%23bar', 'foo%23bar'],
'contains a delimiter ?' => ['?foo%23bar', '?foo%23bar'],
'key-only' => ['k^ey', 'k%5Eey'],
'key-value' => ['k^ey=valu`', 'k%5Eey=valu%60'],
'array-key-only' => ['key[]', 'key%5B%5D'],
'array-key-value' => ['key[]=valu`', 'key%5B%5D=valu%60'],
'complex' => ['k^ey&key[]=valu`&f<>=`bar', 'k%5Eey&key%5B%5D=valu%60&f%3C%3E=%60bar'],
'Percent encode spaces' => ['q=va lue', 'q=va%20lue'],
'Percent encode multibyte' => ['', '%E2%82%AC'],
"Don't encode something that's already encoded" => ['q=va%20lue', 'q=va%20lue'],
'Percent encode invalid percent encodings' => ['q=va%2-lue', 'q=va%2-lue'],
"Don't encode path segments" => ['q=va/lue', 'q=va/lue'],
"Don't encode unreserved chars or sub-delimiters" => [$unreserved, $unreserved],
'Encoded unreserved chars are not decoded' => ['q=v%61lue', 'q=value'],
];
}

public function testCreateFromPairsWithIterable(): void
{
/** @var iterable<int, array{0:string, 1:string|null}> $iterable */
Expand Down

0 comments on commit c1cf91e

Please sign in to comment.