Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Izumi-kun committed Nov 9, 2017
1 parent 85869a3 commit 2c1bf3a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ protected function runLongPoll(float $timeout, $extraParams = [])
} catch (\yii\httpclient\Exception $e) {
return '';
}
if (!$response->getIsOk()) {
return '';
}
$result = $response->getData();
$this->assertArrayHasKey('data', $result);
$this->assertArrayHasKey('params', $result);
Expand Down Expand Up @@ -169,6 +172,33 @@ public function testSend($delay)
$this->expectOutputString($expectedResponse);
}

/**
* @depends testAddEvent
*/
public function testSendTimeout()
{
$event = new Event(['key' => 'newMessage']);
$server = new Server(['timeout' => 2]);
$server->addEvent($event, $event->getState());
$callbackCalled = false;
$server->callback = function (Server $server) use (&$callbackCalled) {
$server->responseData = 'no';
$server->responseParams = ['no' => 'no'];
$callbackCalled = true;
};
$start = time();
$server->send();
$this->assertFalse($callbackCalled);

$waitTime = time() - $start;
$json = <<<JSON
{"data":null,"params":{"event-newMessage":{$event->getState()}}}
JSON;
$leadingZeros = str_repeat('0', $waitTime);
$expectedResponse = $leadingZeros . dechex(strlen($json)) . "\r\n" . $json . "\r\n0\r\n\r\n";
$this->expectOutputString($expectedResponse);
}

public function testSendWithoutEvents()
{
$server = new Server();
Expand Down

0 comments on commit 2c1bf3a

Please sign in to comment.