Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ protected function configure(array $options): void
*/
public function waitForData(float $maxSeconds): ?bool
{
if (!$this->isConnected()) {
return null;
}

return $this->socket->waitForData($maxSeconds);
}
}
4 changes: 4 additions & 0 deletions src/Socket/AbstractSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public function send(string $data): ?int
*/
public function waitForData(float $maxSeconds): ?bool
{
if (null === $this->socket) {
return null;
}

$read = [$this->socket];
$write = null;
$except = null;
Expand Down
2 changes: 2 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function testSend(): void
$instance->addRequestHeader('X-Test', 'Custom Request Header');

self::assertNull($instance->receive(), 'Receive before connect');
self::assertNull($instance->waitForData(0), 'Wait for data before connect');

$success = $instance->connect();
self::assertTrue($success, 'Client can connect to test server');
Expand Down Expand Up @@ -123,6 +124,7 @@ public function testSend(): void
$instance->disconnect();

self::assertFalse($instance->isConnected());
self::assertNull($instance->waitForData(0), 'Wait for data after disconnect');
} finally {
$helper->tearDown();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Socket/ClientSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public function testSendTooEarly(): void
$instance->send('foo');
}

public function testWaitForDataTooEarly(): void
{
$instance = self::getInstance('ws://localhost:8000');

self::assertNull($instance->waitForData(0));
}

/**
* Test the connect, send, receive method.
*/
Expand Down