Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify tests by supporting new Socket API #57

Merged
merged 1 commit into from
Aug 16, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ proxy servers etc.), you can explicitly pass a custom instance of the
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):

```php
$connector = new React\Socket\Connector(null, array(
$connector = new React\Socket\Connector(array(
'dns' => '127.0.0.1',
'tcp' => array(
'bindto' => '192.168.10.1:0'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clue/qdatastream": "^0.8",
"react/event-loop": "^1.2",
"react/promise": "~2.0|~1.1",
"react/socket": "^1.8",
"react/socket": "^1.9",
"react/stream": "^1.2"
},
"require-dev": {
Expand Down
38 changes: 19 additions & 19 deletions tests/FactoryIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Clue\React\Quassel\Factory;
use Clue\React\Quassel\Io\Protocol;
use React\EventLoop\Loop;
use React\Socket\Server;
use React\Socket\SocketServer;
use React\Socket\ConnectionInterface;

class FactoryIntegrationTest extends TestCase
{
public function testCreateClientCreatesConnection()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');
$server->on('connection', $this->expectCallableOnce());

$uri = str_replace('tcp://', '', $server->getAddress());
Expand All @@ -26,7 +26,7 @@ public function testCreateClientCreatesConnection()

public function testCreateClientSendsProbeOverConnection()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$data = $this->expectCallableOnceWith("\x42\xb3\x3f\x00" . "\x00\x00\x00\x02" . "\x80\x00\x00\x01");
$server->on('connection', function (ConnectionInterface $conn) use ($data) {
Expand All @@ -42,7 +42,7 @@ public function testCreateClientSendsProbeOverConnection()

public function testCreateClientResolvesIfServerRespondsWithProbeResponse()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->on('data', function () use ($conn) {
Expand All @@ -62,7 +62,7 @@ public function testCreateClientResolvesIfServerRespondsWithProbeResponse()

public function testCreateClientCreatesSecondConnectionWithoutProbeIfConnectionClosesDuringProbe()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$once = $this->expectCallableOnce();
$server->on('connection', function (ConnectionInterface $conn) use ($once) {
Expand All @@ -81,7 +81,7 @@ public function testCreateClientCreatesSecondConnectionWithoutProbeIfConnectionC

public function testCreateClientRejectsIfServerRespondsWithInvalidData()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->on('data', function () use ($conn) {
Expand All @@ -99,7 +99,7 @@ public function testCreateClientRejectsIfServerRespondsWithInvalidData()

public function testCreateClientWithAuthSendsClientInitAfterProbe()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$data = $this->expectCallableOnceWith($this->callback(function ($packet) {
$data = FactoryIntegrationTest::decode($packet);
Expand All @@ -123,7 +123,7 @@ public function testCreateClientWithAuthSendsClientInitAfterProbe()

public function testCreateClientWithAuthRejectsIfServerClosesAfterClientInit()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->on('data', function () use ($conn) {
Expand All @@ -144,7 +144,7 @@ public function testCreateClientWithAuthRejectsIfServerClosesAfterClientInit()

public function testCreateClientWithAuthRejectsIfServerSendsClientInitRejectAfterClientInit()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->once('data', function () use ($conn) {
Expand All @@ -170,7 +170,7 @@ public function testCreateClientWithAuthRejectsIfServerSendsClientInitRejectAfte

public function testCreateClientWithAuthRejectsIfServerSendsUnknownMessageAfterClientInit()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->once('data', function () use ($conn) {
Expand All @@ -196,7 +196,7 @@ public function testCreateClientWithAuthRejectsIfServerSendsUnknownMessageAfterC

public function testCreateClientWithAuthRejectsIfServerSendsInvalidTruncatedResponseAfterClientInit()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->once('data', function () use ($conn) {
Expand All @@ -217,7 +217,7 @@ public function testCreateClientWithAuthRejectsIfServerSendsInvalidTruncatedResp

public function testCreateClientWithAuthRejectsIfServerSendsClientInitAckNotConfigured()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->once('data', function () use ($conn) {
Expand All @@ -242,7 +242,7 @@ public function testCreateClientWithAuthRejectsIfServerSendsClientInitAckNotConf

public function testCreateClientWithAuthSendsClientLoginAfterClientInit()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect login packet
$data = $this->expectCallableOnceWith($this->callback(function ($packet) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public function testCreateClientWithAuthSendsClientLoginAfterClientInit()

public function testCreateClientRespondsWithHeartBeatResponseAfterHeartBeatRequest()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect heartbeat response packet
$data = $this->expectCallableOnceWith($this->callback(function ($packet) {
Expand Down Expand Up @@ -316,7 +316,7 @@ public function testCreateClientRespondsWithHeartBeatResponseAfterHeartBeatReque

public function testCreateClientDoesNotRespondWithHeartBeatResponseIfPongIsDisabled()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect no message in response
$data = $this->expectCallableNever();
Expand Down Expand Up @@ -350,7 +350,7 @@ public function testCreateClientDoesNotRespondWithHeartBeatResponseIfPongIsDisab

public function testCreateClientSendsHeartBeatRequestAtInterval()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect heartbeat response packet
$data = $this->expectCallableOnceWith($this->callback(function ($packet) {
Expand Down Expand Up @@ -381,7 +381,7 @@ public function testCreateClientSendsHeartBeatRequestAtInterval()

public function testCreateClientSendsNoHeartBeatRequestIfServerKeepsSendingMessages()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect heartbeat response packet
$data = $this->expectCallableNever();
Expand Down Expand Up @@ -412,7 +412,7 @@ public function testCreateClientSendsNoHeartBeatRequestIfServerKeepsSendingMessa

public function testCreateClientClosesWithErrorIfServerDoesNotRespondToHeartBeatRequests()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

$server->on('connection', function (ConnectionInterface $conn) {
$conn->once('data', function () use ($conn) {
Expand All @@ -433,7 +433,7 @@ public function testCreateClientClosesWithErrorIfServerDoesNotRespondToHeartBeat

public function testCreateClientSendsNoHeartBeatRequestIfPingIsDisabled()
{
$server = new Server(0);
$server = new SocketServer('127.0.0.1:0');

// expect heartbeat response packet
$data = $this->expectCallableNever();
Expand Down