Skip to content

Commit 63925d1

Browse files
Arthur Guigandcboden
authored andcommitted
unit tests for py socket
1 parent 803b64c commit 63925d1

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Socket/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function handleData($stream)
1111
// Socket is raw, not using fread as it's interceptable by filters
1212
// See issues #192, #209, and #240
1313
$data = stream_socket_recvfrom($stream, $this->bufferSize);
14-
if( '' != $data || false != $data ){
14+
if( '' !== $data || false !== $data ){
1515
$this->emit('data', array($data, $this));
1616
}
1717
if ('' === $data || false === $data || feof($stream)) {

tests/Socket/ServerTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,40 @@ public function testDataWithNoData()
8484
public function testData()
8585
{
8686
$client = stream_socket_client('tcp://localhost:'.$this->port);
87-
87+
8888
fwrite($client, "foo\n");
89+
90+
$mock = $this->createCallableMock();
91+
$mock
92+
->expects($this->once())
93+
->method('__invoke')
94+
->with("foo\n");
8995

96+
$this->server->on('connection', function ($conn) use ($mock) {
97+
$conn->on('data', $mock);
98+
});
99+
$this->loop->tick();
100+
$this->loop->tick();
101+
}
102+
103+
/**
104+
* Test data sent from python language
105+
*
106+
* @covers React\EventLoop\StreamSelectLoop::tick
107+
* @covers React\Socket\Connection::handleData
108+
*/
109+
public function testDataSentFromPy()
110+
{
111+
$cmd = "python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);s.connect((\"127.0.0.1\", $this->port));s.sendall(\"foo\\n\");s.shutdown(1);'";
112+
exec($cmd);
113+
90114
$mock = $this->createCallableMock();
91115
$mock
92116
->expects($this->once())
93117
->method('__invoke')
94118
->with("foo\n");
95119

120+
96121
$this->server->on('connection', function ($conn) use ($mock) {
97122
$conn->on('data', $mock);
98123
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy