@@ -8,22 +8,21 @@ class GzipCompressorTest extends TestCase
88{
99 private $ compressor ;
1010
11+ /** @var string */
12+ private $ os ;
13+
1114 /**
1215 * @before
1316 */
1417 public function setUpCompressor ()
1518 {
1619 $ this ->compressor = new Compressor (ZLIB_ENCODING_GZIP );
20+ $ this ->os = DIRECTORY_SEPARATOR !== '\\' ? "\x03" : (PHP_VERSION_ID >= 70200 ? "\x0a" : "\x0b" ); // UNIX (0x03) or incorrect TOPS-20(0x0a) or NTFS(0x0b)
1721 }
1822
1923 public function testCompressEmpty ()
2024 {
21- if (DIRECTORY_SEPARATOR === '\\' ) {
22- $ this ->markTestSkipped ('Not supported on Windows ' );
23- }
24-
25- $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
26- $ this ->compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\x03\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00" ));
25+ $ this ->compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ this ->os . "\x03\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00" ));
2726 $ this ->compressor ->on ('end ' , $ this ->expectCallableOnce ());
2827
2928 $ this ->compressor ->end ();
@@ -58,4 +57,41 @@ public function testCompressBig()
5857 // PHP < 5.4 does not support gzdecode(), so let's assert this the other way around…
5958 $ this ->assertEquals (gzencode ($ data ), $ buffered );
6059 }
60+
61+ public function testWriteWillOnlyFlushHeaderByDefaultToBufferDataBeforeFlushing ()
62+ {
63+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP );
64+
65+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ this ->os ));
66+
67+ $ compressor ->write ('hello ' );
68+ }
69+
70+ public function testWriteWithSyncFlushWillFlushHeaderWithFirstChunkImmediately ()
71+ {
72+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_SYNC_FLUSH );
73+
74+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ this ->os . "\xca\x48\xcd\xc9\xc9\x07\x00\x00\x00\xff\xff" ));
75+
76+ $ compressor ->write ('hello ' );
77+ }
78+
79+ public function testWriteWithFinishFlushWillFlushEntireGzipHeaderAndFooterWithFirstChunkImmediately ()
80+ {
81+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_FINISH );
82+
83+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ this ->os . "\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36" . "\x05\x00\x00\x00" ));
84+
85+ $ compressor ->write ('hello ' );
86+ }
87+
88+ public function testWriteAfterFinishFlushWillFlushEntireGzipWithSyncFlushWillFlushEntireGzipHeaderAndFooterAgainImmediately ()
89+ {
90+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_FINISH );
91+ $ compressor ->write ('hello ' );
92+
93+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ this ->os . "\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36" . "\x05\x00\x00\x00" ));
94+
95+ $ compressor ->write ('hello ' );
96+ }
6197}
0 commit comments