forked from clue/reactphp-zlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGzipCompressorTest.php
54 lines (42 loc) · 1.64 KB
/
GzipCompressorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Clue\Tests\React\Zlib;
use Clue\React\Zlib\Compressor;
class GzipCompressorTest extends TestCase
{
private $compressor;
public function setUp()
{
$this->compressor = new Compressor(ZLIB_ENCODING_GZIP);
}
public function testCompressEmpty()
{
$os = DIRECTORY_SEPARATOR === '\\' ? "\x0a" : "\x03"; // NTFS(0x0a) or UNIX (0x03)
$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"));
$this->compressor->on('end', $this->expectCallableOnce());
$this->compressor->end();
}
public function testCompressHelloWorld()
{
$this->compressor->on('data', function ($data) use (&$buffered) {
$buffered .= $data;
});
$this->compressor->on('end', $this->expectCallableOnce());
$this->compressor->end('hello world');
// PHP < 5.4 does not support gzdecode(), so let's assert this the other way around…
$this->assertEquals(gzencode('hello world'), $buffered);
}
public function testCompressBig()
{
$this->compressor->on('data', function ($data) use (&$buffered) {
$buffered .= $data;
});
$this->compressor->on('end', $this->expectCallableOnce());
$data = str_repeat('hello', 100);
foreach (str_split($data, 1) as $byte) {
$this->compressor->write($byte);
}
$this->compressor->end();
// PHP < 5.4 does not support gzdecode(), so let's assert this the other way around…
$this->assertEquals(gzencode($data), $buffered);
}
}