Repository navigation
Expand file tree
/
Copy pathReadableDemultiplexStreamTest.php
More file actions
134 lines (101 loc) · 4.21 KB
/
Copy pathReadableDemultiplexStreamTest.php
File metadata and controls
134 lines (101 loc) · 4.21 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Clue\Tests\React\Docker\Io;
use Clue\React\Docker\Io\ReadableDemultiplexStream;
use Clue\Tests\React\Docker\TestCase;
use React\Stream\ThroughStream;
class ReadableDemultiplexStreamTest extends TestCase
{
private $stream;
private $parser;
/**
* @before
*/
public function setUpParser()
{
$this->stream = new ThroughStream();
$this->parser = new ReadableDemultiplexStream($this->stream);
}
public function testStreamWillForwardEndAndClose()
{
$this->parser->on('data', $this->expectCallableNever());
$this->parser->on('close', $this->expectCallableOnce());
$this->parser->on('end', $this->expectCallableOnce());
$this->stream->emit('end', array());
$this->assertFalse($this->parser->isReadable());
}
public function testStreamWillForwardErrorAndClose()
{
$this->parser->on('error', $this->expectCallableOnce());
$this->parser->on('close', $this->expectCallableOnce());
$this->parser->on('end', $this->expectCallableNever());
$this->stream->emit('error', array(new \RuntimeException('Test')));
$this->assertFalse($this->parser->isReadable());
}
public function testStreamWillEmitErrorWhenEndingWithinStream()
{
$this->parser->on('data', $this->expectCallableNever());
$this->parser->on('error', $this->expectCallableOnce());
$this->parser->on('close', $this->expectCallableOnce());
$this->parser->on('end', $this->expectCallableNever());
$this->stream->emit('data', array('XX'));
$this->stream->emit('end', array());
$this->assertFalse($this->parser->isReadable());
}
public function testStreamWillEmitDataOnCompleteFrame()
{
$this->parser->on('data', $this->expectCallableOnceWith('test'));
$this->stream->emit('data', array("\x01\x00\x00\x00" . "\x00\x00\x00\x04" . "test"));
}
public function testStreamWillNotEmitDataOnIncompleteFrameHeader()
{
$this->parser->on('data', $this->expectCallableNever());
$this->stream->emit('data', array("\x01\0\0\0"));
}
public function testStreamWillNotEmitDataOnIncompleteFramePayload()
{
$this->parser->on('data', $this->expectCallableNever());
$this->stream->emit('data', array("\x01\0\0\0" . "\0\0\0\x04" . "te"));
}
public function testStreamWillEmitDataOnCompleteFrameChunked()
{
$this->parser->on('data', $this->expectCallableOnceWith('test'));
$this->stream->emit('data', array("\x01\x00\x00\x00" . "\x00\x00\x00\x04" . "te"));
$this->stream->emit('data', array("st"));
}
public function testCloseFromDataEventWillStopEmittingFurtherDataEvents()
{
$parser = $this->parser;
$this->parser->on('data', function () use ($parser) {
$parser->close();
});
$this->parser->on('data', $this->expectCallableOnceWith('a'));
$this->stream->emit('data', array("\x01\x00\x00\x00" . "\x00\x00\x00\x01" . "a" . "\x01\x00\x00\x00" . "\x00\x00\x00\x01" . "b"));
}
public function testCloseTwiceWillEmitCloseOnceAndRemoveAllListeners()
{
$this->parser->on('close', $this->expectCallableOnce());
$this->parser->close();
$this->parser->close();
$this->assertEquals(array(), $this->parser->listeners('close'));
}
public function testPipeWillBeForwardedToTargetStream()
{
$target = new ThroughStream();
$target->on('pipe', $this->expectCallableOnceWith($this->parser));
$this->parser->pipe($target);
}
public function testPauseWillBeForwarded()
{
$this->stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$this->stream->expects($this->once())->method('pause');
$this->parser = new ReadableDemultiplexStream($this->stream);
$this->parser->pause();
}
public function testResumeWillBeForwarded()
{
$this->stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
$this->stream->expects($this->once())->method('resume');
$this->parser = new ReadableDemultiplexStream($this->stream);
$this->parser->resume();
}
}