@@ -18,11 +18,7 @@ public function setUpCompressor()
1818
1919 public function testCompressEmpty ()
2020 {
21- if (DIRECTORY_SEPARATOR === '\\' ) {
22- $ this ->markTestSkipped ('Not supported on Windows ' );
23- }
24-
25- $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03" ; // NTFS(0x0a) or UNIX (0x03)
21+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b" : "\x03" ; // NTFS(0x0b) or UNIX (0x03)
2622 $ 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" ));
2723 $ this ->compressor ->on ('end ' , $ this ->expectCallableOnce ());
2824
@@ -58,4 +54,45 @@ public function testCompressBig()
5854 // PHP < 5.4 does not support gzdecode(), so let's assert this the other way around…
5955 $ this ->assertEquals (gzencode ($ data ), $ buffered );
6056 }
57+
58+ public function testWriteWillOnlyFlushHeaderByDefaultToBufferDataBeforeFlushing ()
59+ {
60+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP );
61+
62+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b" : "\x03" ; // NTFS(0x0b) or UNIX (0x03)
63+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os ));
64+
65+ $ compressor ->write ('hello ' );
66+ }
67+
68+ public function testWriteWithSyncFlushWillFlushHeaderWithFirstChunkImmediately ()
69+ {
70+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_SYNC_FLUSH );
71+
72+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b" : "\x03" ; // NTFS(0x0b) or UNIX (0x03)
73+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\xca\x48\xcd\xc9\xc9\x07\x00\x00\x00\xff\xff" ));
74+
75+ $ compressor ->write ('hello ' );
76+ }
77+
78+ public function testWriteWithFinishFlushWillFlushEntireGzipHeaderAndFooterWithFirstChunkImmediately ()
79+ {
80+ $ compressor = new Compressor (ZLIB_ENCODING_GZIP , -1 , ZLIB_FINISH );
81+
82+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b" : "\x03" ; // NTFS(0x0b) or UNIX (0x03)
83+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ 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+ $ os = DIRECTORY_SEPARATOR === '\\' ? "\x0b" : "\x03" ; // NTFS(0x0b) or UNIX (0x03)
94+ $ compressor ->on ('data ' , $ this ->expectCallableOnceWith ("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00" . $ os . "\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36" . "\x05\x00\x00\x00" ));
95+
96+ $ compressor ->write ('hello ' );
97+ }
6198}
0 commit comments