forked from clue/reactphp-zlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeflateDecompressorTest.php
68 lines (52 loc) · 1.85 KB
/
DeflateDecompressorTest.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Clue\Tests\React\Zlib;
use Clue\React\Zlib\Decompressor;
class DeflateDecompressorTest extends TestCase
{
private $decompressor;
public function setUp()
{
$this->decompressor = new Decompressor(ZLIB_ENCODING_RAW);
}
public function testInflateEmpty()
{
$this->decompressor->on('data', $this->expectCallableNever());
$this->decompressor->on('end', $this->expectCallableOnce());
$this->decompressor->end(gzdeflate(''));
}
public function testInflateHelloWorld()
{
$this->decompressor->on('data', function ($data) use (&$buffered) {
$buffered .= $data;
});
$this->decompressor->on('end', $this->expectCallableOnce());
$this->decompressor->end(gzdeflate('hello world'));
$this->assertEquals('hello world', $buffered);
}
public function testInflateBig()
{
$this->decompressor->on('data', function ($data) use (&$buffered) {
$buffered .= $data;
});
$this->decompressor->on('end', $this->expectCallableOnce());
$data = str_repeat('hello', 100);
$bytes = gzdeflate($data);
foreach (str_split($bytes, 1) as $byte) {
$this->decompressor->write($byte);
}
$this->decompressor->end();
$this->assertEquals($data, $buffered);
}
public function testDecompressInvalidDataEmitsError()
{
$this->decompressor->on('data', $this->expectCallableNever());
$this->decompressor->on('error', $this->expectCallableOnce());
$this->decompressor->write('invalid');
}
public function testDecompressInvalidOnEndEmitsError()
{
$this->decompressor->on('data', $this->expectCallableNever());
$this->decompressor->on('error', $this->expectCallableOnce());
$this->decompressor->end('invalid');
}
}