11<?php
22/**
3- * Class QueryTest
3+ * Class QueryUtilTest
44 *
55 * @link https://github.com/guzzle/psr7/blob/c0dcda9f54d145bd4d062a6d15f54931a67732f9/tests/QueryTest.php
66 *
1212
1313namespace chillerlan \HTTPTest \Utils ;
1414
15- use chillerlan \HTTP \Utils \Query ;
15+ use chillerlan \HTTP \Utils \QueryUtil ;
1616use PHPUnit \Framework \TestCase ;
1717use const PHP_QUERY_RFC1738 , PHP_QUERY_RFC3986 ;
1818
1919/**
2020 *
2121 */
22- class QueryTest extends TestCase{
22+ class QueryUtilTest extends TestCase{
2323
2424 public function queryParamDataProvider ():array {
2525 return [
2626 // don't remove empty values
2727 'BOOLEANS_AS_BOOL (no remove) ' => [
28- Query ::BOOLEANS_AS_BOOL ,
28+ QueryUtil ::BOOLEANS_AS_BOOL ,
2929 false ,
3030 ['whatever ' => null , 'nope ' => '' , 'true ' => true , 'false ' => false , 'array ' => ['value ' => false ]],
3131 ],
3232 // bool cast to types
3333 'BOOLEANS_AS_BOOL ' => [
34- Query ::BOOLEANS_AS_BOOL ,
34+ QueryUtil ::BOOLEANS_AS_BOOL ,
3535 true ,
3636 ['true ' => true , 'false ' => false , 'array ' => ['value ' => false ]],
3737 ],
3838 'BOOLEANS_AS_INT ' => [
39- Query ::BOOLEANS_AS_INT ,
39+ QueryUtil ::BOOLEANS_AS_INT ,
4040 true ,
4141 ['true ' => 1 , 'false ' => 0 , 'array ' => ['value ' => 0 ]],
4242 ],
4343 'BOOLEANS_AS_INT_STRING ' => [
44- Query ::BOOLEANS_AS_INT_STRING ,
44+ QueryUtil ::BOOLEANS_AS_INT_STRING ,
4545 true ,
4646 ['true ' => '1 ' , 'false ' => '0 ' , 'array ' => ['value ' => '0 ' ]],
4747 ],
4848 'BOOLEANS_AS_STRING ' => [
49- Query ::BOOLEANS_AS_STRING ,
49+ QueryUtil ::BOOLEANS_AS_STRING ,
5050 true ,
5151 ['true ' => 'true ' , 'false ' => 'false ' , 'array ' => ['value ' => 'false ' ]],
5252 ],
@@ -63,7 +63,7 @@ public function queryParamDataProvider():array{
6363 public function testCleanQueryParams (int $ bool_cast , bool $ remove_empty , array $ expected ):void {
6464 $ data = ['whatever ' => null , 'nope ' => ' ' , 'true ' => true , 'false ' => false , 'array ' => ['value ' => false ]];
6565
66- $ this ::assertSame ($ expected , Query ::cleanParams ($ data , $ bool_cast , $ remove_empty ));
66+ $ this ::assertSame ($ expected , QueryUtil ::cleanParams ($ data , $ bool_cast , $ remove_empty ));
6767 }
6868
6969 public function mergeQueryDataProvider ():array {
@@ -86,27 +86,27 @@ public function mergeQueryDataProvider():array{
8686 * @param string $expected
8787 */
8888 public function testMergeQuery (string $ uri , array $ params , string $ expected ):void {
89- $ merged = Query ::merge ($ uri , $ params );
89+ $ merged = QueryUtil ::merge ($ uri , $ params );
9090 $ this ::assertSame ($ expected , $ merged );
9191 }
9292
9393 public function testBuildQuery ():void {
9494 $ data = ['foo ' => 'bar ' , 'whatever? ' => 'nope! ' ];
9595
96- $ this ::assertSame ('foo=bar&whatever%3F=nope%21 ' , Query ::build ($ data ));
97- $ this ::assertSame ('foo=bar&whatever?=nope! ' , Query ::build ($ data , Query ::NO_ENCODING ));
98- $ this ::assertSame ('foo=bar, whatever?=nope! ' , Query ::build ($ data , Query ::NO_ENCODING , ', ' ));
99- $ this ::assertSame ('foo="bar", whatever?="nope!" ' , Query ::build ($ data , Query ::NO_ENCODING , ', ' , '" ' ));
96+ $ this ::assertSame ('foo=bar&whatever%3F=nope%21 ' , QueryUtil ::build ($ data ));
97+ $ this ::assertSame ('foo=bar&whatever?=nope! ' , QueryUtil ::build ($ data , QueryUtil ::NO_ENCODING ));
98+ $ this ::assertSame ('foo=bar, whatever?=nope! ' , QueryUtil ::build ($ data , QueryUtil ::NO_ENCODING , ', ' ));
99+ $ this ::assertSame ('foo="bar", whatever?="nope!" ' , QueryUtil ::build ($ data , QueryUtil ::NO_ENCODING , ', ' , '" ' ));
100100
101101 $ data ['florps ' ] = ['nope ' , 'nope ' , 'nah ' ];
102102 $ this ::assertSame (
103103 'florps="nah", florps="nope", florps="nope", foo="bar", whatever?="nope!" ' ,
104- Query ::build ($ data , Query ::NO_ENCODING , ', ' , '" ' )
104+ QueryUtil ::build ($ data , QueryUtil ::NO_ENCODING , ', ' , '" ' )
105105 );
106106 }
107107
108108 public function testBuildQuerySort ():void {
109- $ this ::assertSame ('a=2&b=1&b=2&b=3&c=1&d=4 ' , Query ::build (['c ' => 1 , 'a ' => 2 , 'b ' => [3 , 1 , 2 ], 'd ' => 4 ]));
109+ $ this ::assertSame ('a=2&b=1&b=2&b=3&c=1&d=4 ' , QueryUtil ::build (['c ' => 1 , 'a ' => 2 , 'b ' => [3 , 1 , 2 ], 'd ' => 4 ]));
110110 }
111111
112112 public function parseQueryProvider ():array {
@@ -135,49 +135,49 @@ public function parseQueryProvider():array{
135135 * @dataProvider parseQueryProvider
136136 */
137137 public function testParsesQueries (string $ input , array $ output ):void {
138- $ this ::assertSame ($ output , Query ::parse ($ input ));
138+ $ this ::assertSame ($ output , QueryUtil ::parse ($ input ));
139139 }
140140
141141 /**
142142 * @dataProvider parseQueryProvider
143143 */
144144 public function testParsesAndBuildsQueries (string $ input ): void {
145- $ result = Query ::parse ($ input , Query ::NO_ENCODING );
145+ $ result = QueryUtil ::parse ($ input , QueryUtil ::NO_ENCODING );
146146
147- $ this ::assertSame ($ input , Query ::build ($ result , Query ::NO_ENCODING ));
147+ $ this ::assertSame ($ input , QueryUtil ::build ($ result , QueryUtil ::NO_ENCODING ));
148148 }
149149
150150 public function testDoesNotDecode ():void {
151- $ this ::assertSame (['foo%20 ' => 'bar ' ], Query ::parse ('foo%20=bar ' , Query ::NO_ENCODING ));
151+ $ this ::assertSame (['foo%20 ' => 'bar ' ], QueryUtil ::parse ('foo%20=bar ' , QueryUtil ::NO_ENCODING ));
152152 }
153153
154154 public function testEncodesWithRfc1738 ():void {
155- $ this ::assertSame ('foo+bar=baz%2B ' , Query ::build (['foo bar ' => 'baz+ ' ], PHP_QUERY_RFC1738 ));
155+ $ this ::assertSame ('foo+bar=baz%2B ' , QueryUtil ::build (['foo bar ' => 'baz+ ' ], PHP_QUERY_RFC1738 ));
156156 }
157157
158158 public function testEncodesWithRfc3986 ():void {
159- $ this ::assertSame ('foo%20bar=baz%2B ' , Query ::build (['foo bar ' => 'baz+ ' ], PHP_QUERY_RFC3986 ));
159+ $ this ::assertSame ('foo%20bar=baz%2B ' , QueryUtil ::build (['foo bar ' => 'baz+ ' ], PHP_QUERY_RFC3986 ));
160160 }
161161
162162 public function testDoesNotEncode ():void {
163- $ this ::assertSame ('foo bar=baz+ ' , Query ::build (['foo bar ' => 'baz+ ' ], Query ::NO_ENCODING ));
163+ $ this ::assertSame ('foo bar=baz+ ' , QueryUtil ::build (['foo bar ' => 'baz+ ' ], QueryUtil ::NO_ENCODING ));
164164 }
165165
166166 public function testCanControlDecodingType ():void {
167- $ this ::assertSame ('foo+bar ' , Query ::parse ('var=foo+bar ' , PHP_QUERY_RFC3986 )['var ' ]);
168- $ this ::assertSame ('foo bar ' , Query ::parse ('var=foo+bar ' , PHP_QUERY_RFC1738 )['var ' ]);
167+ $ this ::assertSame ('foo+bar ' , QueryUtil ::parse ('var=foo+bar ' , PHP_QUERY_RFC3986 )['var ' ]);
168+ $ this ::assertSame ('foo bar ' , QueryUtil ::parse ('var=foo+bar ' , PHP_QUERY_RFC1738 )['var ' ]);
169169 }
170170
171171 public function testBuildBooleans ():void {
172- $ this ::assertSame ('false=0&true=1 ' , Query ::build (['true ' => true , 'false ' => false ]));
172+ $ this ::assertSame ('false=0&true=1 ' , QueryUtil ::build (['true ' => true , 'false ' => false ]));
173173
174174 $ this ::assertSame (
175175 'bar=0&bar=false&foo=1&foo=true ' ,
176- Query ::build (['foo ' => [true , 'true ' ], 'bar ' => [false , 'false ' ]], PHP_QUERY_RFC1738 )
176+ QueryUtil ::build (['foo ' => [true , 'true ' ], 'bar ' => [false , 'false ' ]], PHP_QUERY_RFC1738 )
177177 );
178178 }
179179
180180 public function testParseDoesTrimQuestionMark ():void {
181- $ this ::assertSame (Query ::parse ('?q=a ' ), ['q ' => 'a ' ]);
181+ $ this ::assertSame (QueryUtil ::parse ('?q=a ' ), ['q ' => 'a ' ]);
182182 }
183183}
0 commit comments