Skip to content

Commit

Permalink
Fix writeBufferInput() to properly use BufferInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jun 4, 2018
1 parent 6fa93ac commit 216352d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 5 additions & 3 deletions examples/11-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Clue\React\Quassel\Factory;
use Clue\React\Quassel\Client;
use Clue\React\Quassel\Io\Protocol;
use Clue\React\Quassel\Models\BufferInfo;

require __DIR__ . '/../vendor/autoload.php';

Expand Down Expand Up @@ -90,9 +91,10 @@
}

foreach ($message['SessionState']['BufferInfos'] as $buffer) {
if ($buffer['type'] === 2) { // type == 4 for user
var_dump('requesting IrcChannel for ' . $buffer['name']);
$client->writeInitRequest('IrcChannel', $buffer['network'] . '/' . $buffer['id']);
assert($buffer instanceof BufferInfo);
if ($buffer->getType() === BufferInfo::TYPE_CHANNEL) {
var_dump('requesting IrcChannel for ' . $buffer->getName());
$client->writeInitRequest('IrcChannel', $buffer->getNetworkId() . '/' . $buffer->getId());
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Io/Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public function __construct()
);

$this->userTypeWriter = array(
'BufferInfo' => function ($data, Writer $writer) {
$writer->writeUInt($data['id']);
$writer->writeUInt($data['network']);
$writer->writeUShort($data['type']);
$writer->writeUInt($data['group']);
$writer->writeQByteArray($data['name']);
'BufferInfo' => function (BufferInfo $buffer, Writer $writer) {
$writer->writeUInt($buffer->getId());
$writer->writeUInt($buffer->getNetworkId());
$writer->writeUShort($buffer->getType());
$writer->writeUInt($buffer->getGroupId());
$writer->writeQByteArray($buffer->getName());
},
'BufferId' => function ($data, Writer $writer) {
$writer->writeUInt($data);
Expand Down
14 changes: 14 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Clue\React\Quassel\Client;
use Clue\React\Quassel\Io\DatastreamProtocol;
use Clue\React\Quassel\Io\Protocol;
use Clue\React\Quassel\Models\BufferInfo;
use React\Stream\ThroughStream;

class ClientTest extends TestCase
Expand Down Expand Up @@ -193,6 +195,18 @@ public function testWriteCoreSetupData()
$this->client->writeCoreSetupData('user', 'pass', 'PQSql', array('password' => 'test'));
}

public function testWriteBufferInputWritesToStreamOnce()
{
$this->protocol = new DatastreamProtocol();
$this->client = new Client($this->stream, $this->protocol, $this->splitter);

$this->stream->expects($this->once())->method('write');

$bufferInfo = new BufferInfo(1, 2, 3, 4, '#test');

$this->client->writeBufferInput($bufferInfo, 'Hello!');
}

public function testWriteHeartBeatReply()
{
$dt = new \DateTime();
Expand Down

0 comments on commit 216352d

Please sign in to comment.