Skip to content

Commit 03be64b

Browse files
committed
:octocat: merge_query() coverage
1 parent d571551 commit 03be64b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Diff for: tests/Psr7/MessageHelpersTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use function chillerlan\HTTP\Psr17\create_stream;
2020
use function chillerlan\HTTP\Psr7\{
2121
build_http_query, clean_query_params, decompress_content, get_json, get_xml,
22-
message_to_string, normalize_request_headers, r_rawurlencode
22+
merge_query, message_to_string, normalize_request_headers, r_rawurlencode
2323
};
2424

2525
use const chillerlan\HTTP\Psr7\{BOOLEANS_AS_BOOL, BOOLEANS_AS_INT, BOOLEANS_AS_INT_STRING, BOOLEANS_AS_STRING};
@@ -75,6 +75,26 @@ public function testCleanQueryParams(array $expected, int $bool_cast, bool $remo
7575
$this->assertSame($expected, clean_query_params($data, $bool_cast, $remove_empty));
7676
}
7777

78+
public function mergeQueryDataProvider():array{
79+
$uri = 'http://localhost/whatever/';
80+
$params = ['foo' => 'bar'];
81+
82+
return [
83+
'add nothing and clear the trailing question mark' => [$uri.'?', [], $uri],
84+
'add to URI without query' => [$uri, $params, $uri.'?foo=bar'],
85+
'overwrite existing param' => [$uri.'?foo=nope', $params, $uri.'?foo=bar'],
86+
'add to existing param' => [$uri.'?what=nope', $params, $uri.'?foo=bar&what=nope'],
87+
];
88+
}
89+
90+
/**
91+
* @dataProvider mergeQueryDataProvider
92+
*/
93+
public function testMergeQuery($uri, $params, $expected){
94+
$merged = merge_query($uri, $params);
95+
$this->assertSame($expected, $merged);
96+
}
97+
7898
public function rawurlencodeDataProvider(){
7999
return [
80100
'string' => ['some test string!', 'some%20test%20string%21'],

0 commit comments

Comments
 (0)