-
Notifications
You must be signed in to change notification settings - Fork 5
/
FunctionalDecoderTest.php
87 lines (66 loc) · 2.32 KB
/
FunctionalDecoderTest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Clue\Tests\React\Tar;
use Clue\React\Tar\Decoder;
use React\EventLoop\Loop;
use React\Stream\ReadableResourceStream;
class FunctionDecoderTest extends TestCase
{
private $decoder;
/**
* @before
*/
public function setUpDecoderAndLoop()
{
$this->decoder = new Decoder();
}
/**
* @doesNotPerformAssertions
*/
public function testAliceBob()
{
$stream = $this->createStream('alice-bob.tar');
$stream->pipe($this->decoder);
Loop::run();
}
/**
* @doesNotPerformAssertions
*/
public function testAliceBobWithSmallBufferSize()
{
// a tiny buffer size will emit *lots* of individual chunks, but the parser should work as expected
$stream = $this->createStream('alice-bob.tar', 11);
$stream->pipe($this->decoder);
Loop::run();
}
public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()
{
$stream = $this->createStream('single-empty.tar');
$never = $this->expectCallableNever();
$once = $this->expectCallableOnce();
$that = $this;
$this->decoder->on('entry', $this->expectCallableOnce());
$this->decoder->on('entry', function ($entry, $stream) use ($that, $never, $once) {
$that->assertEquals('empty', $entry['filename']);
$that->assertEquals(0, $entry['size']);
$that->assertTrue($stream->isReadable());
$stream->on('error', $never);
$stream->on('data', $never);
$stream->on('close', $once);
});
$this->decoder->on('close', $this->expectCallableOnce());
$this->decoder->on('error', $this->expectCallableNever());
$stream->pipe($this->decoder);
Loop::run();
}
public function testCompleteEndSingleEmptyBehavesSameAsStreaming()
{
$this->decoder->on('entry', $this->expectCallableOnce());
$this->decoder->on('close', $this->expectCallableOnce());
$this->decoder->on('error', $this->expectCallableNever());
$this->decoder->end(file_get_contents(__DIR__ . '/fixtures/single-empty.tar'));
}
private function createStream($name, $readChunkSize = null)
{
return new ReadableResourceStream(fopen(__DIR__ . '/fixtures/' . $name, 'r'), null, $readChunkSize);
}
}