|
19 | 19 | use function chillerlan\HTTP\Psr17\create_stream;
|
20 | 20 | use function chillerlan\HTTP\Psr7\{
|
21 | 21 | 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 |
23 | 23 | };
|
24 | 24 |
|
25 | 25 | 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
|
75 | 75 | $this->assertSame($expected, clean_query_params($data, $bool_cast, $remove_empty));
|
76 | 76 | }
|
77 | 77 |
|
| 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 | + |
78 | 98 | public function rawurlencodeDataProvider(){
|
79 | 99 | return [
|
80 | 100 | 'string' => ['some test string!', 'some%20test%20string%21'],
|
|
0 commit comments