aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-10 10:13:42 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-10 10:13:42 +0100
commit3fd0fcc1ac381d85da0296d3a32611ab5350cd19 (patch)
tree2e20414e383a23f33de9bde14c06c62bc69e0a05
parentf5cf84e5f51490f2aa88eb375bfabc1b2fcb3678 (diff)
downloadWebsocket-3fd0fcc1ac381d85da0296d3a32611ab5350cd19.zip
Websocket-3fd0fcc1ac381d85da0296d3a32611ab5350cd19.tar.gz
Websocket-3fd0fcc1ac381d85da0296d3a32611ab5350cd19.tar.bz2
chore(php) Update to PHP 7.
-rw-r--r--Source/Client.php2
-rw-r--r--Source/Protocol/Generic.php2
-rw-r--r--Source/Protocol/Hybi00.php6
-rw-r--r--Source/Protocol/Rfc6455.php2
-rw-r--r--Test/Unit/Client.php28
-rw-r--r--Test/Unit/Connection.php2
-rw-r--r--Test/Unit/Protocol/Hybi00.php8
-rw-r--r--Test/Unit/Protocol/Rfc6455.php12
8 files changed, 25 insertions, 37 deletions
diff --git a/Source/Client.php b/Source/Client.php
index 637e598..0e73ace 100644
--- a/Source/Client.php
+++ b/Source/Client.php
@@ -100,7 +100,7 @@ class Client extends Connection
/**
* Connect, i.e. open the connection and do handshake.
*/
- public function connect(): HoaSocket\Connection
+ public function connect(): self
{
$this->doHandshake();
diff --git a/Source/Protocol/Generic.php b/Source/Protocol/Generic.php
index 370c669..54af5a3 100644
--- a/Source/Protocol/Generic.php
+++ b/Source/Protocol/Generic.php
@@ -84,7 +84,7 @@ abstract class Generic
int $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
bool $end = true,
bool $mask = false
- ): int;
+ );
/**
* Send a message to a node (if not specified, current node).
diff --git a/Source/Protocol/Hybi00.php b/Source/Protocol/Hybi00.php
index ca25f62..13f9f97 100644
--- a/Source/Protocol/Hybi00.php
+++ b/Source/Protocol/Hybi00.php
@@ -53,8 +53,8 @@ class Hybi00 extends Generic
*/
public function doHandshake(Http\Request $request): void
{
- $key1 = $request['sec-websocket-key1'];
- $key2 = $request['sec-websocket-key2'];
+ $key1 = $request['sec-websocket-key1'] ?? '';
+ $key2 = $request['sec-websocket-key2'] ?? '';
$key3 = $request->getBody();
$location = $request['host'] . $request->getUrl();
$keynumb1 = (float) preg_replace('#[^0-9]#', '', $key1);
@@ -131,7 +131,7 @@ class Hybi00 extends Generic
int $opcode = -1,
bool $end = true,
bool $mask = false
- ): int {
+ ) {
return $this->getConnection()->writeAll(
chr(0) . $message . chr(255)
);
diff --git a/Source/Protocol/Rfc6455.php b/Source/Protocol/Rfc6455.php
index c5f6a37..e29167f 100644
--- a/Source/Protocol/Rfc6455.php
+++ b/Source/Protocol/Rfc6455.php
@@ -217,7 +217,7 @@ class Rfc6455 extends Generic
int $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
bool $end = true,
bool $mask = false
- ): int {
+ ) {
$fin = true === $end ? 0x1 : 0x0;
$rsv1 = 0x0;
$rsv2 = 0x0;
diff --git a/Test/Unit/Client.php b/Test/Unit/Client.php
index 6b6cfeb..ebd0980 100644
--- a/Test/Unit/Client.php
+++ b/Test/Unit/Client.php
@@ -148,14 +148,12 @@ class Client extends Test\Unit\Suite
$this->calling($client)->doHandshake = function () use (&$called): void {
$called = true;
-
- return;
}
)
->when($result = $client->connect())
->then
- ->variable($result)
- ->isNull()
+ ->object($result)
+ ->isIdenticalTo($client)
->boolean($called)
->isTrue();
}
@@ -182,8 +180,6 @@ class Client extends Test\Unit\Suite
$self
->object($_node)
->isIdenticalTo($node);
-
- return;
}
)
->when($result = $client->receive())
@@ -216,8 +212,6 @@ class Client extends Test\Unit\Suite
$self
->object($_node)
->isIdenticalTo($node);
-
- return;
}
)
->when($result = $client->receive())
@@ -248,10 +242,10 @@ class Client extends Test\Unit\Suite
$this->calling($sock)->isSecured = false,
$this->calling($socket)->getSocket = $sock,
- $this->calling($socket)->connect = function () use (&$calledA) {
+ $this->calling($socket)->connect = function () use (&$calledA, $socket) {
$calledA = true;
- return true;
+ return $socket;
},
$this->calling($socket)->setStreamBlocking = function ($_block) use (&$calledB, $self) {
$calledB = true;
@@ -360,10 +354,10 @@ class Client extends Test\Unit\Suite
$this->calling($sock)->isSecured = true,
$this->calling($socket)->getSocket = $sock,
- $this->calling($socket)->connect = function () use (&$calledA) {
+ $this->calling($socket)->connect = function () use (&$calledA, $socket) {
$calledA = true;
- return true;
+ return $socket;
},
$this->calling($socket)->enableEncryption = function ($_enable, $_type, $_sessionStream) use (&$calledB, $self, $socket) {
$calledB = true;
@@ -484,9 +478,9 @@ class Client extends Test\Unit\Suite
$this->calling($sock)->isSecured = false,
$this->calling($socket)->getSocket = $sock,
- $this->calling($socket)->connect = null,
+ $this->calling($socket)->connect = $socket,
$this->calling($socket)->enableEncryption = null,
- $this->calling($socket)->setStreamBlocking = null
+ $this->calling($socket)->setStreamBlocking = true
)
->exception(function () use ($client): void {
$this->invoke($client)->doHandshake();
@@ -548,7 +542,7 @@ class Client extends Test\Unit\Suite
$this->calling($sock)->isSecured = true,
$this->calling($socket)->getSocket = $sock,
- $this->calling($socket)->connect = true,
+ $this->calling($socket)->connect = $socket,
$this->calling($socket)->enableEncryption = function ($_enable, $_type, $_sessionStream) use ($self, $socket) {
$self
->boolean($_enable)
@@ -659,10 +653,10 @@ class Client extends Test\Unit\Suite
},
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($socket)->mute = function () use (&$calledB): void {
+ $this->calling($socket)->mute = function () use (&$calledB) {
$calledB = true;
- return;
+ return true;
},
$this->calling($socket)->setStreamTimeout = function ($_second, $_millisecond) use (&$calledC, $self) {
$calledC = true;
diff --git a/Test/Unit/Connection.php b/Test/Unit/Connection.php
index 7643250..16ff0b9 100644
--- a/Test/Unit/Connection.php
+++ b/Test/Unit/Connection.php
@@ -1233,8 +1233,6 @@ class Connection extends Test\Unit\Suite
->when($result = $closure($opcode, $end))
->then
- ->integer($result)
- ->isEqualTo(42)
->boolean($called)
->isTrue();
}
diff --git a/Test/Unit/Protocol/Hybi00.php b/Test/Unit/Protocol/Hybi00.php
index e5b0661..72574ad 100644
--- a/Test/Unit/Protocol/Hybi00.php
+++ b/Test/Unit/Protocol/Hybi00.php
@@ -103,14 +103,14 @@ class Hybi00 extends Test\Unit\Suite
),
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self): void {
+ $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self) {
$calledA = true;
$self
->boolean($handshake)
->isTrue();
- return;
+ return true;
},
$this->calling($socket)->writeAll = function ($data) use (&$calledB, $self, $challenge): void {
$calledB = true;
@@ -125,8 +125,6 @@ class Hybi00 extends Test\Unit\Suite
'Sec-WebSocket-Location: ws://example.org/foobar' . CRLF . CRLF .
$challenge . CRLF
);
-
- return;
}
)
->when($result = $protocol->doHandshake($request))
@@ -146,7 +144,7 @@ class Hybi00 extends Test\Unit\Suite
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket),
- $this->calling($socket)->read = null
+ $this->calling($socket)->read = ''
)
->when($result = $protocol->readFrame())
->then
diff --git a/Test/Unit/Protocol/Rfc6455.php b/Test/Unit/Protocol/Rfc6455.php
index 0d24d53..cfeac57 100644
--- a/Test/Unit/Protocol/Rfc6455.php
+++ b/Test/Unit/Protocol/Rfc6455.php
@@ -134,14 +134,14 @@ class Rfc6455 extends Test\Unit\Suite
$challenge = base64_encode(sha1($request['sec-websocket-key'] . SUT::GUID, true)),
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self): void {
+ $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self) {
$calledA = true;
$self
->boolean($handshake)
->isTrue();
- return;
+ return true;
},
$this->calling($socket)->writeAll = function ($_data) use (&$calledB, $self, $challenge): void {
$calledB = true;
@@ -155,8 +155,6 @@ class Rfc6455 extends Test\Unit\Suite
'Sec-WebSocket-Accept: ' . $challenge . CRLF .
'Sec-WebSocket-Version: 13' . CRLF . CRLF
);
-
- return;
}
)
->when($result = $protocol->doHandshake($request))
@@ -176,7 +174,7 @@ class Rfc6455 extends Test\Unit\Suite
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket),
- $this->calling($socket)->read = null
+ $this->calling($socket)->read = ''
)
->when($result = $protocol->readFrame())
->then
@@ -1080,7 +1078,7 @@ class Rfc6455 extends Test\Unit\Suite
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket),
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $code, $reason, $mask): void {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $code, $reason, $mask) {
$called = true;
$self
@@ -1093,7 +1091,7 @@ class Rfc6455 extends Test\Unit\Suite
->boolean($_mask)
->isEqualTo($mask);
- return;
+ return strlen($_message);
}
)
->when($result = $protocol->close($code, $reason, $mask))