10
10
11
11
namespace chillerlan \HTTPTest \Utils ;
12
12
13
- use TypeError ;
13
+ use RuntimeException , TypeError ;
14
14
15
15
use function chillerlan \HTTP \Utils \{
16
16
decompress_content , get_json , get_xml , message_to_string , parseUrl , r_rawurlencode ,
17
17
uriIsAbsolute , uriIsAbsolutePathReference , uriIsDefaultPort , uriIsNetworkPathReference ,
18
18
uriIsRelativePathReference , uriWithoutQueryValue , uriWithQueryValue
19
19
};
20
20
21
+ use function extension_loaded , function_exists ;
21
22
use const chillerlan \HTTP \Utils \URI_DEFAULT_PORTS ;
22
23
23
24
class MessageHelpersTest extends TestAbstract{
@@ -106,6 +107,7 @@ public function testMessageToString():void{
106
107
107
108
public function decompressDataProvider ():array {
108
109
return [
110
+ 'br ' => ['brotli_compress ' , 'br ' ],
109
111
'compress ' => ['gzcompress ' , 'compress ' ],
110
112
'deflate ' => ['gzdeflate ' , 'deflate ' ],
111
113
'gzip ' => ['gzencode ' , 'gzip ' ],
@@ -117,7 +119,14 @@ public function decompressDataProvider():array{
117
119
* @dataProvider decompressDataProvider
118
120
*/
119
121
public function testDecompressContent (string $ fn , string $ encoding ):void {
120
- $ data = $ expected = str_repeat ('compressed string ' , 100 );
122
+
123
+ // https://github.com/kjdev/php-ext-brotli
124
+ if ($ encoding === 'br ' && (!extension_loaded ('brotli ' ) || !function_exists ('brotli_compress ' ))){
125
+ $ this ::markTestSkipped ('N/A (ext-brotli not isntalled) ' );
126
+ }
127
+
128
+ $ data = str_repeat ('compressed string ' , 100 );
129
+ $ expected = $ data ;
121
130
$ response = $ this ->responseFactory ->createResponse ();
122
131
123
132
if ($ fn ){
@@ -130,6 +139,22 @@ public function testDecompressContent(string $fn, string $encoding):void{
130
139
$ this ::assertSame ($ expected , decompress_content ($ response ));
131
140
}
132
141
142
+ public function testDecompressContentUnableToDecompressBrotliException ():void {
143
+
144
+ if (extension_loaded ('brotli ' ) && function_exists ('brotli_uncompress ' )){
145
+ $ this ::markTestSkipped ('N/A (ext-brotli isntalled) ' );
146
+ }
147
+
148
+ $ this ->expectException (RuntimeException::class);
149
+ $ this ->expectExceptionMessage ('cannot decompress brotli compressed message body ' );
150
+
151
+ $ response = $ this ->responseFactory
152
+ ->createResponse ()
153
+ ->withHeader ('Content-Encoding ' , 'br ' );
154
+
155
+ decompress_content ($ response );
156
+ }
157
+
133
158
public function testUriIsAbsolute ():void {
134
159
$ this ::assertTrue (uriIsAbsolute ($ this ->uriFactory ->createUri ('http://example.org ' )));
135
160
$ this ::assertFalse (uriIsAbsolute ($ this ->uriFactory ->createUri ('//example.org ' )));
0 commit comments