|
4 | 4 | use Clue\React\Quassel\Io\Protocol; |
5 | 5 | use Clue\QDataStream\QVariant; |
6 | 6 | use Clue\QDataStream\Types; |
| 7 | +use React\Stream\ThroughStream; |
7 | 8 |
|
8 | 9 | class ClientTest extends TestCase |
9 | 10 | { |
10 | 11 | public function setUp() |
11 | 12 | { |
12 | | - $this->stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->setMethods(array('write', 'end', 'close', 'pause', 'resume', 'isReadable', 'isWritable'))->getMock(); |
| 13 | + $this->stream = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock(); |
13 | 14 | $this->protocol = $this->getMockBuilder('Clue\React\Quassel\Io\Protocol')->disableOriginalConstructor()->getMock(); |
14 | 15 | $this->splitter = $this->getMockBuilder('Clue\React\Quassel\Io\PacketSplitter')->disableOriginalConstructor()->getMock(); |
15 | 16 |
|
@@ -61,34 +62,49 @@ public function testPipeWillReturnDestStream() |
61 | 62 |
|
62 | 63 | public function testCloseEventWillBeForwarded() |
63 | 64 | { |
| 65 | + $this->stream = new ThroughStream(); |
| 66 | + $this->client = new Client($this->stream, $this->protocol, $this->splitter); |
| 67 | + |
64 | 68 | $this->client->on('close', $this->expectCallableOnce()); |
65 | 69 | $this->stream->emit('close'); |
66 | 70 | } |
67 | 71 |
|
68 | 72 | public function testDrainEventWillBeForwarded() |
69 | 73 | { |
| 74 | + $this->stream = new ThroughStream(); |
| 75 | + $this->client = new Client($this->stream, $this->protocol, $this->splitter); |
| 76 | + |
70 | 77 | $this->client->on('drain', $this->expectCallableOnce()); |
71 | 78 | $this->stream->emit('drain'); |
72 | 79 | } |
73 | 80 |
|
74 | 81 | public function testEndEventWillBeForwardedAndClose() |
75 | 82 | { |
| 83 | + $this->stream = new ThroughStream(); |
| 84 | + $this->client = new Client($this->stream, $this->protocol, $this->splitter); |
| 85 | + |
76 | 86 | $this->client->on('end', $this->expectCallableOnce()); |
77 | | - $this->stream->expects($this->once())->method('close'); |
78 | | - $this->stream->emit('end'); |
| 87 | + $this->stream->on('close', $this->expectCallableOnce()); |
| 88 | + $this->stream->end(); |
79 | 89 | } |
80 | 90 |
|
81 | 91 | public function testErrorEventWillBeForwardedAndClose() |
82 | 92 | { |
| 93 | + $this->stream = new ThroughStream(); |
| 94 | + $this->client = new Client($this->stream, $this->protocol, $this->splitter); |
| 95 | + |
83 | 96 | $e = new \RuntimeException(); |
84 | 97 |
|
85 | 98 | $this->client->on('error', $this->expectCallableOnceWith($e)); |
86 | | - $this->stream->expects($this->once())->method('close'); |
| 99 | + $this->stream->on('close', $this->expectCallableOnce()); |
87 | 100 | $this->stream->emit('error', array($e)); |
88 | 101 | } |
89 | 102 |
|
90 | 103 | public function testDataEventWillNotBeForwardedIfItIsAnIncompletePacket() |
91 | 104 | { |
| 105 | + $this->stream = new ThroughStream(); |
| 106 | + $this->client = new Client($this->stream, $this->protocol, $this->splitter); |
| 107 | + |
92 | 108 | $this->splitter->expects($this->once())->method('push')->with("hello", array($this->client, 'handlePacket')); |
93 | 109 | $this->client->on('data', $this->expectCallableNever()); |
94 | 110 |
|
|
0 commit comments