aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-08 15:55:02 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-08 15:55:02 +0100
commitf5cf84e5f51490f2aa88eb375bfabc1b2fcb3678 (patch)
tree2f33025a45c6c9c06e550014d20ffb7baf6abbaf
parent53b1f48aab6f89c9c1ae25958b34a02f353d8ee4 (diff)
downloadWebsocket-f5cf84e5f51490f2aa88eb375bfabc1b2fcb3678.zip
Websocket-f5cf84e5f51490f2aa88eb375bfabc1b2fcb3678.tar.gz
Websocket-f5cf84e5f51490f2aa88eb375bfabc1b2fcb3678.tar.bz2
chore(php) Update to PHP 7.
-rw-r--r--Bin/Client.php19
-rw-r--r--Source/Client.php93
-rw-r--r--Source/Connection.php136
-rw-r--r--Source/Exception/BadProtocol.php5
-rw-r--r--Source/Exception/CloseError.php16
-rw-r--r--Source/Exception/Exception.php7
-rw-r--r--Source/Exception/InvalidMessage.php5
-rw-r--r--Source/Node.php72
-rw-r--r--Source/Protocol/Generic.php72
-rw-r--r--Source/Protocol/Hybi00.php65
-rw-r--r--Source/Protocol/Rfc6455.php80
-rw-r--r--Source/Server.php29
-rw-r--r--Source/Socket.php35
-rw-r--r--Test/Integration/Protocol/Rfc6455.php32
-rw-r--r--Test/Unit/Client.php67
-rw-r--r--Test/Unit/Connection.php113
-rw-r--r--Test/Unit/Exception/BadProtocol.php5
-rw-r--r--Test/Unit/Exception/CloseError.php9
-rw-r--r--Test/Unit/Exception/Exception.php5
-rw-r--r--Test/Unit/Exception/InvalidMessage.php5
-rw-r--r--Test/Unit/Node.php41
-rw-r--r--Test/Unit/Protocol/Generic.php5
-rw-r--r--Test/Unit/Protocol/Hybi00.php29
-rw-r--r--Test/Unit/Protocol/Rfc6455.php109
-rw-r--r--Test/Unit/Server.php21
-rw-r--r--Test/Unit/Socket.php31
26 files changed, 411 insertions, 695 deletions
diff --git a/Bin/Client.php b/Bin/Client.php
index 2e51e20..338b057 100644
--- a/Bin/Client.php
+++ b/Bin/Client.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,16 +46,11 @@ use Hoa\Websocket;
* Class \Hoa\Websocket\Bin\Client.
*
* Basic WebSocket client.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Client extends Console\Dispatcher\Kit
{
/**
* Options description.
- *
- * @var array
*/
protected $options = [
['server', Console\GetOption::REQUIRED_ARGUMENT, 's'],
@@ -65,10 +62,8 @@ class Client extends Console\Dispatcher\Kit
/**
* The entry method.
- *
- * @return int
*/
- public function main()
+ public function main(): int
{
$server = '127.0.0.1:8889';
@@ -110,15 +105,13 @@ class Client extends Console\Dispatcher\Kit
$client->close();
- return;
+ return 0;
}
/**
* The command usage.
- *
- * @return int
*/
- public function usage()
+ public function usage(): void
{
echo
'Usage : websocket:client <options>', "\n",
@@ -127,8 +120,6 @@ class Client extends Console\Dispatcher\Kit
's' => 'Server URI (default: 127.0.0.1:8889).',
'help' => 'This help.'
]), "\n";
-
- return;
}
}
diff --git a/Source/Client.php b/Source/Client.php
index 4a8969b..637e598 100644
--- a/Source/Client.php
+++ b/Source/Client.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,30 +47,21 @@ use Hoa\Socket as HoaSocket;
* Class \Hoa\Websocket\Client.
*
* A cross-protocol Websocket client.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Client extends Connection
{
/**
* Endpoint.
- *
- * @var string
*/
protected $_endPoint = null;
/**
* Host name.
- *
- * @var string
*/
protected $_host = null;
/**
* Response (mainly parser).
- *
- * @var \Hoa\Http\Response
*/
protected $_response = null;
@@ -76,15 +69,10 @@ class Client extends Connection
/**
* Create a Websocket client.
- *
- * @param \Hoa\Socket\Client $client Client.
- * @param string $endPoint End-point.
- * @param \Hoa\Http\Response $request Response parser.
- * @throws \Hoa\Socket\Exception
*/
public function __construct(
HoaSocket\Client $client,
- $endPoint = null,
+ string $endPoint = null,
Http\Response $response = null
) {
parent::__construct($client);
@@ -111,32 +99,27 @@ class Client extends Connection
/**
* Connect, i.e. open the connection and do handshake.
- *
- * @return void
*/
- public function connect()
+ public function connect(): HoaSocket\Connection
{
- return $this->doHandshake();
+ $this->doHandshake();
+
+ return $this;
}
/**
* Override the parent run() method to open the connection.
- *
- * @return void
*/
- public function run()
+ public function run(): void
{
$this->connect();
-
- return parent::run();
+ parent::run();
}
/**
* Receive data. Fire listeners.
- *
- * @return void
*/
- public function receive()
+ public function receive(): void
{
$connection = $this->getConnection();
$node = $connection->getCurrentNode();
@@ -145,18 +128,14 @@ class Client extends Connection
$this->_run($node);
} while (
false === $connection->isDisconnected() &&
- true !== $node->isMessageComplete()
+ true !== $node->isMessageComplete()
);
}
/**
* Try the handshake by trying different protocol implementation.
- *
- * @return void
- * @throws \Hoa\Websocket\Exception
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- protected function doHandshake()
+ protected function doHandshake(): void
{
$connection = $this->getConnection();
$connection->connect();
@@ -197,8 +176,8 @@ class Client extends Connection
if ($response::STATUS_SWITCHING_PROTOCOLS !== $response['status'] ||
'websocket' !== strtolower($response['upgrade']) ||
- 'upgrade' !== strtolower($response['connection']) ||
- $expected !== $response['sec-websocket-accept']) {
+ 'upgrade' !== strtolower($response['connection']) ||
+ $expected !== $response['sec-websocket-accept']) {
throw new Exception\BadProtocol(
'Handshake has failed, the server did not return a valid ' .
'response.' . "\n\n" .
@@ -220,16 +199,12 @@ class Client extends Connection
'open',
new Event\Bucket()
);
-
- return;
}
/**
* Generate a challenge.
- *
- * @return string
*/
- public function getNewChallenge()
+ public function getNewChallenge(): string
{
static $_tail = ['A', 'Q', 'g', 'w'];
@@ -240,13 +215,8 @@ class Client extends Connection
/**
* Close a specific node/connection.
- *
- * @param int $code Code (please, see
- * self::CLOSE_* constants).
- * @param string $reason Reason.
- * @return void
*/
- public function close($code = self::CLOSE_NORMAL, $reason = null)
+ public function close(int $code = self::CLOSE_NORMAL, string $reason = null): void
{
$connection = $this->getConnection();
$protocol = $connection->getCurrentNode()->getProtocolImplementation();
@@ -259,16 +229,13 @@ class Client extends Connection
$connection->setStreamTimeout(0, 2 * 15000); // 2 * MLS (on FreeBSD)
$connection->read(1);
- return $connection->disconnect();
+ $connection->disconnect();
}
/**
* Set end-point.
- *
- * @param string $endPoint End-point.
- * @return string
*/
- protected function setEndPoint($endPoint)
+ protected function setEndPoint(string $endPoint): ?string
{
$old = $this->_endPoint;
$this->_endPoint = $endPoint;
@@ -278,21 +245,16 @@ class Client extends Connection
/**
* Get end-point.
- *
- * @return string
*/
- public function getEndPoint()
+ public function getEndPoint(): string
{
return $this->_endPoint;
}
/**
* Set response (mainly parser).
- *
- * @param \Hoa\Http\Response $response Response.
- * @return \Hoa\Http\Response
*/
- public function setResponse(Http\Response $response)
+ public function setResponse(Http\Response $response): ?Http\Response
{
$old = $this->_response;
$this->_response = $response;
@@ -302,21 +264,16 @@ class Client extends Connection
/**
* Get response.
- *
- * @return \Hoa\Http\Response
*/
- public function getResponse()
+ public function getResponse(): Http\Response
{
return $this->_response;
}
/**
* Set host.
- *
- * @param string $host Host.
- * @return string
*/
- public function setHost($host)
+ public function setHost(string $host): ?string
{
$old = $this->_host;
$this->_host = $host;
@@ -329,13 +286,11 @@ class Client extends Connection
*
* @return string
*/
- public function getHost()
+ public function getHost(): ?string
{
return
null !== $this->_host
? $this->_host
- : (isset($_SERVER['HTTP_HOST'])
- ? $_SERVER['HTTP_HOST']
- : null);
+ : ($_SERVER['HTTP_HOST'] ?? null);
}
}
diff --git a/Source/Connection.php b/Source/Connection.php
index ce1e355..08ee1a5 100644
--- a/Source/Connection.php
+++ b/Source/Connection.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,141 +46,100 @@ use Hoa\Socket as HoaSocket;
* Class \Hoa\Websocket\Connection.
*
* A cross-protocol Websocket connection.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
-abstract class Connection
- extends HoaSocket\Connection\Handler
- implements Event\Listenable
+abstract class Connection extends HoaSocket\Connection\Handler implements Event\Listenable
{
use Event\Listens;
/**
* Opcode: continuation frame.
- *
- * @const int
*/
- const OPCODE_CONTINUATION_FRAME = 0x0;
+ public const OPCODE_CONTINUATION_FRAME = 0x0;
/**
* Opcode: text frame.
- *
- * @const int
*/
- const OPCODE_TEXT_FRAME = 0x1;
+ public const OPCODE_TEXT_FRAME = 0x1;
/**
* Opcode: binary frame.
- *
- * @const int
*/
- const OPCODE_BINARY_FRAME = 0x2;
+ public const OPCODE_BINARY_FRAME = 0x2;
/**
* Opcode: connection close.
- *
- * @const int
*/
- const OPCODE_CONNECTION_CLOSE = 0x8;
+ public const OPCODE_CONNECTION_CLOSE = 0x8;
/**
* Opcode: ping.
- *
- * @const int
*/
- const OPCODE_PING = 0x9;
+ public const OPCODE_PING = 0x9;
/**
* Opcode: pong.
- *
- * @const int
*/
- const OPCODE_PONG = 0xa;
+ public const OPCODE_PONG = 0xa;
/**
* Close: normal.
- *
- * @const int
*/
- const CLOSE_NORMAL = 1000;
+ public const CLOSE_NORMAL = 1000;
/**
* Close: going away.
- *
- * @const int
*/
- const CLOSE_GOING_AWAY = 1001;
+ public const CLOSE_GOING_AWAY = 1001;
/**
* Close: protocol error.
- *
- * @const int
*/
- const CLOSE_PROTOCOL_ERROR = 1002;
+ public const CLOSE_PROTOCOL_ERROR = 1002;
/**
* Close: data error.
- *
- * @const int
*/
- const CLOSE_DATA_ERROR = 1003;
+ public const CLOSE_DATA_ERROR = 1003;
/**
* Close: status error.
- *
- * @const int
*/
- const CLOSE_STATUS_ERROR = 1005;
+ public const CLOSE_STATUS_ERROR = 1005;
/**
* Close: abnormal.
- *
- * @const int
*/
- const CLOSE_ABNORMAL = 1006;
+ public const CLOSE_ABNORMAL = 1006;
/**
* Close: message error.
- *
- * @const int
*/
- const CLOSE_MESSAGE_ERROR = 1007;
+ public const CLOSE_MESSAGE_ERROR = 1007;
/**
* Close: policy error.
- *
- * @const int
*/
- const CLOSE_POLICY_ERROR = 1008;
+ public const CLOSE_POLICY_ERROR = 1008;
/**
* Close: message too big.
- *
- * @const int
*/
- const CLOSE_MESSAGE_TOO_BIG = 1009;
+ public const CLOSE_MESSAGE_TOO_BIG = 1009;
/**
* Close: extension missing.
- *
- * @const int
*/
- const CLOSE_EXTENSION_MISSING = 1010;
+ public const CLOSE_EXTENSION_MISSING = 1010;
/**
* Close: server error.
- *
- * @const int
*/
- const CLOSE_SERVER_ERROR = 1011;
+ public const CLOSE_SERVER_ERROR = 1011;
/**
* Close: TLS.
- *
- * @const int
*/
- const CLOSE_TLS = 1015;
+ public const CLOSE_TLS = 1015;
@@ -186,9 +147,6 @@ abstract class Connection
* Create a websocket connection.
* 6 events can be listened: open, message, binary-message, ping, close and
* error.
- *
- * @param \Hoa\Socket\Connection $connection Connection.
- * @throws \Hoa\Socket\Exception
*/
public function __construct(HoaSocket\Connection $connection)
{
@@ -214,11 +172,8 @@ abstract class Connection
/**
* Run a node.
- *
- * @param \Hoa\Socket\Node $node Node.
- * @return void
*/
- protected function _run(HoaSocket\Node $node)
+ protected function _run(HoaSocket\Node $node): void
{
try {
if (FAILED === $node->getHandshake()) {
@@ -261,6 +216,7 @@ abstract class Connection
case self::OPCODE_BINARY_FRAME:
$fromBinary = true;
+ // no break
case self::OPCODE_TEXT_FRAME:
if (0x1 === $frame['fin']) {
if (0 < $node->getNumberOfFragments()) {
@@ -320,6 +276,7 @@ abstract class Connection
$fromText = true;
+ // no break
case self::OPCODE_CONTINUATION_FRAME:
if (false === $fromText) {
if (0 === $node->getNumberOfFragments()) {
@@ -393,8 +350,8 @@ abstract class Connection
case self::OPCODE_PING:
$message = &$frame['message'];
- if (0x0 === $frame['fin'] ||
- 0x7d < $frame['length']) {
+ if (0x0 === $frame['fin'] ||
+ 0x7d < $frame['length']) {
$this->close(self::CLOSE_PROTOCOL_ERROR);
break;
@@ -429,8 +386,8 @@ abstract class Connection
case self::OPCODE_CONNECTION_CLOSE:
$length = &$frame['length'];
- if (0x1 === $length ||
- 0x7d < $length) {
+ if (0x1 === $length ||
+ 0x7d < $length) {
$this->close(self::CLOSE_PROTOCOL_ERROR);
break;
@@ -444,10 +401,10 @@ abstract class Connection
$_code = unpack('nc', substr($message, 0, 2));
$code = &$_code['c'];
- if (1000 > $code ||
+ if (1000 > $code ||
(1004 <= $code && $code <= 1006) ||
(1012 <= $code && $code <= 1016) ||
- 5000 <= $code) {
+ 5000 <= $code) {
$this->close(self::CLOSE_PROTOCOL_ERROR);
break;
@@ -512,20 +469,13 @@ abstract class Connection
/**
* Try the handshake by trying different protocol implementation.
- *
- * @return void
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- abstract protected function doHandshake();
+ abstract protected function doHandshake(): void;
/**
* Send a message.
- *
- * @param string $message Message.
- * @param \Hoa\Socket\Node $node Node.
- * @return \Closure
*/
- protected function _send($message, HoaSocket\Node $node)
+ protected function _send(string $message, HoaSocket\Node $node)
{
$mustMask = $this instanceof Client;
@@ -543,19 +493,12 @@ abstract class Connection
/**
* Send a message to a specific node/connection.
- *
- * @param string $message Message.
- * @param \Hoa\Socket\Node $node Node (if null, current node).
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of
- * the message.
- * @return void
*/
public function send(
- $message,
+ string $message,
HoaSocket\Node $node = null,
- $opcode = self::OPCODE_TEXT_FRAME,
- $end = true
+ int $opcode = self::OPCODE_TEXT_FRAME,
+ bool $end = true
) {
$send = parent::send($message, $node);
@@ -569,13 +512,8 @@ abstract class Connection
/**
* Close a specific node/connection.
* It is just a “inline” method, a shortcut.
- *
- * @param int $code Code (please, see
- * self::CLOSE_* constants).
- * @param string $reason Reason.
- * @return void
*/
- public function close($code = self::CLOSE_NORMAL, $reason = null)
+ public function close(int $code = self::CLOSE_NORMAL, string $reason = null): void
{
$connection = $this->getConnection();
$protocol = $connection->getCurrentNode()->getProtocolImplementation();
@@ -595,7 +533,5 @@ abstract class Connection
} finally {
$connection->disconnect();
}
-
- return;
}
}
diff --git a/Source/Exception/BadProtocol.php b/Source/Exception/BadProtocol.php
index 0d40a81..3a5c7e1 100644
--- a/Source/Exception/BadProtocol.php
+++ b/Source/Exception/BadProtocol.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,9 +42,6 @@ namespace Hoa\Websocket\Exception;
* Class \Hoa\Websocket\Exception\BadProtocol.
*
* Extending the \Hoa\Websocket\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class BadProtocol extends Exception
{
diff --git a/Source/Exception/CloseError.php b/Source/Exception/CloseError.php
index 979863b..a447a84 100644
--- a/Source/Exception/CloseError.php
+++ b/Source/Exception/CloseError.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,9 +42,6 @@ namespace Hoa\Websocket\Exception;
* Class \Hoa\Websocket\Exception\CloseError.
*
* Extending the \Hoa\Websocket\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class CloseError extends Exception
{
@@ -50,19 +49,14 @@ class CloseError extends Exception
* Error code.
*
* One of the \Hoa\Websocket\Connection::CLOSE_* constants.
- *
- * @var int
*/
protected $_errorCode = null;
/**
* Set the error code.
- *
- * @param int $code Code.
- * @return int
*/
- public function setErrorCode($code)
+ public function setErrorCode(int $code): ?int
{
$old = $this->_errorCode;
$this->_errorCode = $code;
@@ -72,10 +66,8 @@ class CloseError extends Exception
/**
* Get the error code.
- *
- * @return int
*/
- public function getErrorCode()
+ public function getErrorCode(): ?int
{
return $this->_errorCode;
}
diff --git a/Source/Exception/Exception.php b/Source/Exception/Exception.php
index 4743037..2e1a612 100644
--- a/Source/Exception/Exception.php
+++ b/Source/Exception/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,9 +45,6 @@ use Hoa\Exception as HoaException;
* Class \Hoa\Websocket\Exception.
*
* Extending the \Hoa\Exception\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Exception extends HoaException
{
@@ -54,4 +53,4 @@ class Exception extends HoaException
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Websocket\Exception\Exception');
+Consistency::flexEntity(Exception::class);
diff --git a/Source/Exception/InvalidMessage.php b/Source/Exception/InvalidMessage.php
index 221f858..bb63e76 100644
--- a/Source/Exception/InvalidMessage.php
+++ b/Source/Exception/InvalidMessage.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,9 +42,6 @@ namespace Hoa\Websocket\Exception;
* Class \Hoa\Websocket\Exception\InvalidMessage.
*
* Extending the \Hoa\Websocket\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class InvalidMessage extends Exception
{
diff --git a/Source/Node.php b/Source/Node.php
index 682e786..bb282a3 100644
--- a/Source/Node.php
+++ b/Source/Node.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -42,51 +44,36 @@ use Hoa\Socket as HoaSocket;
* Class \Hoa\Websocket\Node.
*
* Describe a WebSocket node.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Node extends HoaSocket\Node
{
/**
* Protocol implementation.
- *
- * @var \Hoa\Websocket\Protocol\Generic
*/
protected $_protocol = null;
/**
* Whether the handshake succeed.
- *
- * @var bool
*/
protected $_handshake = false;
/**
* Fragments of message.
- *
- * @var string
*/
protected $_messageFragments = null;
/**
* Number of fragments.
- *
- * @var int
*/
protected $_numberOfFragments = 0;
/**
* Whether the message is complete or not.
- *
- * @var bool
*/
protected $_complete = true;
/**
* Whether the message is binary or not.
- *
- * @var bool
*/
protected $_isBinary = false;
@@ -94,11 +81,8 @@ class Node extends HoaSocket\Node
/**
* Set protocol implementation.
- *
- * @param \Hoa\Websocket\Protocol\Generic $protocol Protocol.
- * @return \Hoa\Websocket\Protocol\Generic
*/
- public function setProtocolImplementation(Protocol\Generic $protocol)
+ public function setProtocolImplementation(Protocol\Generic $protocol): ?Protocol\Generic
{
$old = $this->_protocol;
$this->_protocol = $protocol;
@@ -108,21 +92,16 @@ class Node extends HoaSocket\Node
/**
* Get protocol implementation.
- *
- * @return \Hoa\Websocket\Protocol\Generic
*/
- public function getProtocolImplementation()
+ public function getProtocolImplementation(): ?Protocol\Generic
{
return $this->_protocol;
}
/**
* Set handshake success.
- *
- * @param bool $handshake Handshake.
- * @return bool
*/
- public function setHandshake($handshake)
+ public function setHandshake(bool $handshake): bool
{
$old = $this->_handshake;
$this->_handshake = $handshake;
@@ -132,21 +111,16 @@ class Node extends HoaSocket\Node
/**
* Whether the handshake succeed.
- *
- * @return bool
*/
- public function getHandshake()
+ public function getHandshake(): bool
{
return $this->_handshake;
}
/**
* Append a fragment to a message (if we have fragmentation).
- *
- * @param string $fragment Fragment.
- * @return string
*/
- public function appendMessageFragment($fragment)
+ public function appendMessageFragment(string $fragment): string
{
++$this->_numberOfFragments;
@@ -155,31 +129,24 @@ class Node extends HoaSocket\Node
/**
* Get the fragmented message.
- *
- * @return string
*/
- public function getFragmentedMessage()
+ public function getFragmentedMessage(): ?string
{
return $this->_messageFragments;
}
/**
* Get number of fragments.
- *
- * @return int
*/
- public function getNumberOfFragments()
+ public function getNumberOfFragments(): int
{
return $this->_numberOfFragments;
}
/**
* Set whether the message is complete or not.
- *
- * @param bool $complete Is it complete?
- * @return bool
*/
- public function setComplete($complete)
+ public function setComplete(bool $complete): bool
{
$old = $this->_complete;
$this->_complete = $complete;
@@ -189,21 +156,16 @@ class Node extends HoaSocket\Node
/**
* Check if the message is complete or not.
- *
- * @return bool
*/
- public function isMessageComplete()
+ public function isMessageComplete(): bool
{
return $this->_complete;
}
/**
* Whether the message is binary or not.
- *
- * @param bool $binary Binary.
- * @return bool
*/
- public function setBinary($binary)
+ public function setBinary(bool $binary): bool
{
$old = $this->_isBinary;
$this->_isBinary = $binary;
@@ -213,26 +175,20 @@ class Node extends HoaSocket\Node
/**
* Check if the message is binary or not.
- *
- * @return bool
*/
- public function isBinary()
+ public function isBinary(): bool
{
return $this->_isBinary;
}
/**
* Clear the fragmentation.
- *
- * @return void
*/
- public function clearFragmentation()
+ public function clearFragmentation(): void
{
$this->_messageFragments = null;
$this->_numberOfFragments = 0;
$this->_isBinary = false;
$this->_complete = true;
-
- return;
}
}
diff --git a/Source/Protocol/Generic.php b/Source/Protocol/Generic.php
index 22f6680..370c669 100644
--- a/Source/Protocol/Generic.php
+++ b/Source/Protocol/Generic.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -44,16 +46,11 @@ use Hoa\Websocket;
* Class \Hoa\Websocket\Protocol\Generic.
*
* An abstract protocol implementation.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
abstract class Generic
{
/**
* Connection.
- *
- * @var \Hoa\Socket\Connection
*/
protected $_connection = null;
@@ -61,8 +58,6 @@ abstract class Generic
/**
* Construct the protocol implementation.
- *
- * @param \Hoa\Socket\Connection $connection Connection.
*/
public function __construct(Socket\Connection $connection)
{
@@ -73,76 +68,47 @@ abstract class Generic
/**
* Do the handshake.
- *
- * @param \Hoa\Http\Request $request Request.
- * @return void
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- abstract public function doHandshake(Http\Request $request);
+ abstract public function doHandshake(Http\Request $request): void;
/**
* Read a frame.
- *
- * @return array
- * @throws \Hoa\Websocket\Exception
*/
- abstract public function readFrame();
+ abstract public function readFrame(): array;
/**
* Write a frame.
- *
- * @param string $message Message.
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return int
- * @throws \Hoa\Websocket\Exception
*/
abstract public function writeFrame(
- $message,
- $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
- $end = true,
- $mask = false
- );
+ string $message,
+ 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).
- *
- * @param string $message Message.
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return void
*/
abstract public function send(
- $message,
- $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
- $end = true,
- $mask = false
- );
+ string $message,
+ int $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
+ bool $end = true,
+ bool $mask = false
+ ): void;
/**
* Close a specific node/connection.
- *
- * @param int $code Code (please, see
- * \Hoa\Websocket\Connection::CLOSE_*
- * constants).
- * @param string $reason Reason.
- * @param bool $mask Whether the message will be masked or not.
- * @return void
*/
abstract public function close(
- $code = Websocket\Connection::CLOSE_NORMAL,
- $reason = null,
- $mask = false
- );
+ int $code = Websocket\Connection::CLOSE_NORMAL,
+ string $reason = null,
+ bool $mask = false
+ ): void;
/**
* Get the socket connection.
- *
- * @return \Hoa\Socket\Connection
*/
- protected function getConnection()
+ protected function getConnection(): Socket\Connection
{
return $this->_connection;
}
diff --git a/Source/Protocol/Hybi00.php b/Source/Protocol/Hybi00.php
index f729f77..ca25f62 100644
--- a/Source/Protocol/Hybi00.php
+++ b/Source/Protocol/Hybi00.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,20 +45,13 @@ use Hoa\Websocket;
* Class \Hoa\Websocket\Protocol\Hybi00.
*
* Protocol implementation: draft-ietf-hybi-thewebsocketprotocol-00.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Hybi00 extends Generic
{
/**
* Do the handshake.
- *
- * @param \Hoa\Http\Request $request Request.
- * @return void
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- public function doHandshake(Http\Request $request)
+ public function doHandshake(Http\Request $request): void
{
$key1 = $request['sec-websocket-key1'];
$key2 = $request['sec-websocket-key2'];
@@ -93,16 +88,12 @@ class Hybi00 extends Generic
$response . "\r\n"
);
$connection->getCurrentNode()->setHandshake(SUCCEED);
-
- return;
}
/**
* Read a frame.
- *
- * @return array
*/
- public function readFrame()
+ public function readFrame(): array
{
$buffer = $this->getConnection()->read(2048);
$length = strlen($buffer) - 2;
@@ -134,19 +125,13 @@ class Hybi00 extends Generic
/**
* Write a frame.
- *
- * @param string $message Message.
- * @param int $opcode Opcode (useless here).
- * @param bool $end Whether it is the last frame of the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return int
*/
public function writeFrame(
- $message,
- $opcode = -1,
- $end = true,
- $mask = false
- ) {
+ string $message,
+ int $opcode = -1,
+ bool $end = true,
+ bool $mask = false
+ ): int {
return $this->getConnection()->writeAll(
chr(0) . $message . chr(255)
);
@@ -154,35 +139,23 @@ class Hybi00 extends Generic
/**
* Send a message to a node (if not specified, current node).
- *
- * @param string $message Message.
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return void
*/
- public function send($message, $opcode = -1, $end = true, $mask = false)
- {
+ public function send(
+ string $message,
+ int $opcode = -1,
+ bool $end = true,
+ bool $mask = false
+ ): void {
$this->writeFrame($message);
-
- return;
}
/**
* Close a specific node/connection.
- *
- * @param int $code Code (please, see
- * \Hoa\Websocket\Connection::CLOSE_*
- * constants).
- * @param string $reason Reason.
- * @param bool $mask Whether the message will be masked or not.
- * @return void
*/
public function close(
- $code = Websocket\Connection::CLOSE_NORMAL,
- $reason = null,
- $mask = false
- ) {
- return;
+ int $code = Websocket\Connection::CLOSE_NORMAL,
+ string $reason = null,
+ bool $mask = false
+ ): void {
}
}
diff --git a/Source/Protocol/Rfc6455.php b/Source/Protocol/Rfc6455.php
index efa926e..c5f6a37 100644
--- a/Source/Protocol/Rfc6455.php
+++ b/Source/Protocol/Rfc6455.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,29 +45,20 @@ use Hoa\Websocket;
* Class \Hoa\Websocket\Protocol\Rfc6455.
*
* Protocol implementation: RFC6455.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Rfc6455 extends Generic
{
/**
* GUID.
- *
- * @const string
*/
- const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
+ public const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
/**
* Do the handshake.
- *
- * @param \Hoa\Http\Request $request Request.
- * @return void
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- public function doHandshake(Http\Request $request)
+ public function doHandshake(Http\Request $request): void
{
if (!isset($request['sec-websocket-key'])) {
throw new Websocket\Exception\BadProtocol(
@@ -103,17 +96,12 @@ class Rfc6455 extends Generic
'Sec-WebSocket-Version: 13' . "\r\n\r\n"
);
$connection->getCurrentNode()->setHandshake(SUCCEED);
-
- return;
}
/**
* Read a frame.
- *
- * @return array
- * @throws \Hoa\Websocket\Exception\CloseError
*/
- public function readFrame()
+ public function readFrame(): array
{
$connection = $this->getConnection();
$out = [];
@@ -130,11 +118,11 @@ class Rfc6455 extends Generic
$out['rsv1'] = ($handle >> 6) & 0x1;
$out['rsv2'] = ($handle >> 5) & 0x1;
$out['rsv3'] = ($handle >> 4) & 0x1;
- $out['opcode'] = $handle & 0xf;
+ $out['opcode'] = $handle & 0xf;
$handle = ord($connection->read(1));
$out['mask'] = ($handle >> 7) & 0x1;
- $out['length'] = $handle & 0x7f;
+ $out['length'] = $handle & 0x7f;
$length = &$out['length'];
if (0x0 !== $out['rsv1'] || 0x0 !== $out['rsv2'] || 0x0 !== $out['rsv3']) {
@@ -223,19 +211,13 @@ class Rfc6455 extends Generic
/**
* Write a frame.
- *
- * @param string $message Message.
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return int
*/
public function writeFrame(
- $message,
- $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
- $end = true,
- $mask = false
- ) {
+ string $message,
+ int $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
+ bool $end = true,
+ bool $mask = false
+ ): int {
$fin = true === $end ? 0x1 : 0x0;
$rsv1 = 0x0;
$rsv2 = 0x0;
@@ -243,7 +225,7 @@ class Rfc6455 extends Generic
$mask = true === $mask ? 0x1 : 0x0;
$length = strlen($message);
$out = chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -277,10 +259,8 @@ class Rfc6455 extends Generic
/**
* Get a random masking key.
- *
- * @return array
*/
- public function getMaskingKey()
+ public function getMaskingKey(): array
{
if (true === function_exists('openssl_random_pseudo_bytes')) {
$maskingKey = array_map(
@@ -302,23 +282,15 @@ class Rfc6455 extends Generic
/**
* Send a message.
- *
- * @param string $message Message.
- * @param int $opcode Opcode.
- * @param bool $end Whether it is the last frame of
- * the message.
- * @param bool $mask Whether the message will be masked or not.
- * @return void
- * @throws \Hoa\Websocket\Exception\InvalidMessage
*/
public function send(
- $message,
- $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
- $end = true,
- $mask = false
- ) {
+ string $message,
+ int $opcode = Websocket\Connection::OPCODE_TEXT_FRAME,
+ bool $end = true,
+ bool $mask = false
+ ): void {
if (Websocket\Connection::OPCODE_TEXT_FRAME === $opcode &&
- true === $end &&
+ true === $end &&
false === (bool) preg_match('//u', $message)) {
throw new Websocket\Exception\InvalidMessage(
'Message “%s” is not in UTF-8, cannot send it.',
@@ -330,8 +302,6 @@ class Rfc6455 extends Generic
}
$this->writeFrame($message, $opcode, $end, $mask);
-
- return;
}
/**
@@ -345,17 +315,15 @@ class Rfc6455 extends Generic
* @return void
*/
public function close(
- $code = Websocket\Connection::CLOSE_NORMAL,
- $reason = null,
- $mask = false
- ) {
+ int $code = Websocket\Connection::CLOSE_NORMAL,
+ string $reason = null,
+ bool $mask = false
+ ): void {
$this->writeFrame(
pack('n', $code) . $reason,
Websocket\Connection::OPCODE_CONNECTION_CLOSE,
true,
$mask
);
-
- return;
}
}
diff --git a/Source/Server.php b/Source/Server.php
index 0495841..a9b31e2 100644
--- a/Source/Server.php
+++ b/Source/Server.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -43,16 +45,11 @@ use Hoa\Socket as HoaSocket;
* Class \Hoa\Websocket\Server.
*
* A cross-protocol Websocket server.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Server extends Connection
{
/**
* Request (mainly parser).
- *
- * @var \Hoa\Http\Request
*/
protected $_request = null;
@@ -60,10 +57,6 @@ class Server extends Connection
/**
* Create a Websocket server.
- *
- * @param \Hoa\Socket\Server $server Server.
- * @param \Hoa\Http\Request $request Request parser.
- * @throws \Hoa\Socket\Exception
*/
public function __construct(
HoaSocket\Server $server,
@@ -82,15 +75,12 @@ class Server extends Connection
/**
* Try the handshake by trying different protocol implementation.
- *
- * @return void
- * @throws \Hoa\Websocket\Exception\BadProtocol
*/
- protected function doHandshake()
+ protected function doHandshake(): void
{
$connection = $this->getConnection();
- if (true === $connection->getSocket()->isSecured() &&
+ if (true === $connection->getSocket()->isSecured() &&
false === $connection->isEncrypted()) {
$connection->enableEncryption(true, $connection::ENCRYPTION_TLS);
}
@@ -119,17 +109,12 @@ class Server extends Connection
throw new Exception\BadProtocol('All protocol failed.', 1);
}
}
-
- return;
}
/**
* Set request (mainly parser).
- *
- * @param \Hoa\Http\Request $request Request.
- * @return \Hoa\Http\Request
*/
- public function setRequest(Http\Request $request)
+ public function setRequest(Http\Request $request): ?Http\Request
{
$old = $this->_request;
$this->_request = $request;
@@ -139,10 +124,8 @@ class Server extends Connection
/**
* Get request.
- *
- * @return \Hoa\Http\Request
*/
- public function getRequest()
+ public function getRequest(): Http\Request
{
return $this->_request;
}
diff --git a/Source/Socket.php b/Source/Socket.php
index 8c6c371..13b8cde 100644
--- a/Source/Socket.php
+++ b/Source/Socket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -42,29 +44,20 @@ use Hoa\Socket as HoaSocket;
* Class \Hoa\Websocket\Socket.
*
* WebSocket specific socket and transports.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Socket extends HoaSocket
{
/**
* Endpoint.
- *
- * @var string
*/
- protected $_endPoint = '/';
+ protected $_endPoint = null;
/**
* Constructor
- *
- * @param string $uri Socket URI.
- * @param boolean $secured Whether the connection is secured.
- * @param string $endPoint Endpoint.
*/
- public function __construct($uri, $secured = false, $endPoint = '/')
+ public function __construct(string $uri, bool $secured = false, string $endPoint = '/')
{
parent::__construct($uri);
@@ -76,21 +69,16 @@ class Socket extends HoaSocket
/**
* Retrieve the websocket endpoint
- *
- * @return string
*/
- public function getEndPoint()
+ public function getEndPoint(): string
{
return $this->_endPoint;
}
/**
* Factory to create a valid `Hoa\Socket\Socket` object.
- *
- * @param string $socketUri URI of the socket to connect to.
- * @return void
*/
- public static function transportFactory($socketUri)
+ public static function transportFactory(string $socketUri): self
{
$parsed = parse_url($socketUri);
@@ -108,16 +96,15 @@ class Socket extends HoaSocket
: false;
$port =
- isset($parsed['port'])
- ? $parsed['port']
- : (true === $secure
+ $parsed['port']
+ ?? (true === $secure
? 443
: 80);
return new static(
'tcp://' . $parsed['host'] . ':' . $port,
$secure,
- (isset($parsed['path']) ? $parsed['path'] : '/') .
+ ($parsed['path'] ?? '/') .
(isset($parsed['query']) ? '?' . $parsed['query'] : '')
);
}
@@ -126,5 +113,5 @@ class Socket extends HoaSocket
/**
* Register `ws://` and `wss://` transports.
*/
-HoaSocket\Transport::register('ws', ['Hoa\Websocket\Socket', 'transportFactory']);
-HoaSocket\Transport::register('wss', ['Hoa\Websocket\Socket', 'transportFactory']);
+HoaSocket\Transport::register('ws', [Socket::class, 'transportFactory']);
+HoaSocket\Transport::register('wss', [Socket::class, 'transportFactory']);
diff --git a/Test/Integration/Protocol/Rfc6455.php b/Test/Integration/Protocol/Rfc6455.php
index 375f74b..dda4904 100644
--- a/Test/Integration/Protocol/Rfc6455.php
+++ b/Test/Integration/Protocol/Rfc6455.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -46,19 +48,18 @@ use Hoa\Websocket;
*
* Test suite of the RFC6455 protocol.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Rfc6455 extends Test\Integration\Suite
{
- public function case_server()
+ public function case_server(): void
{
$numberOfTestsToCompute = $this->getNumberOfTestsToCompute();
$server = new Websocket\Server(new Socket\Server('ws://127.0.0.1:1234'));
$server->on(
'ping',
- function (Event\Bucket $bucket) use (&$numberOfTestsToCompute) {
+ function (Event\Bucket $bucket) use (&$numberOfTestsToCompute): void {
$bucket->getSource()->close();
if ('skip' === substr($bucket->getData()['message'], 0, 4)) {
@@ -72,7 +73,7 @@ class Rfc6455 extends Test\Integration\Suite
);
$server->on(
'message',
- function (Event\Bucket $bucket) use (&$numberOfTestsToCompute) {
+ function (Event\Bucket $bucket) use (&$numberOfTestsToCompute): void {
$source = $bucket->getSource();
$message = $bucket->getData()['message'];
$source->send($message);
@@ -90,7 +91,7 @@ class Rfc6455 extends Test\Integration\Suite
);
$server->on(
'binary-message',
- function (Event\Bucket $bucket) use (&$numberOfTestsToCompute) {
+ function (Event\Bucket $bucket) use (&$numberOfTestsToCompute): void {
$source = $bucket->getSource();
$message = $bucket->getData()['message'];
$source->send(
@@ -112,7 +113,7 @@ class Rfc6455 extends Test\Integration\Suite
);
$server->on(
'error',
- function (Event\Bucket $bucket) {
+ function (Event\Bucket $bucket): void {
throw $bucket->getData()['exception'];
}
);
@@ -284,7 +285,7 @@ class Rfc6455 extends Test\Integration\Suite
->send('close');
}
- public function case_send_fragmented_message()
+ public function case_send_fragmented_message(): void
{
$this
->given(
@@ -321,7 +322,7 @@ class Rfc6455 extends Test\Integration\Suite
);
}
- public function case_send_fragmented_text_frame_with_an_empty_payload()
+ public function case_send_fragmented_text_frame_with_an_empty_payload(): void
{
$this
->given(
@@ -373,7 +374,7 @@ class Rfc6455 extends Test\Integration\Suite
);
}
- public function case_send_fragmented_text_frame_with_a_valid_UTF_8_payload()
+ public function case_send_fragmented_text_frame_with_a_valid_UTF_8_payload(): void
{
$this
->given(
@@ -413,7 +414,7 @@ class Rfc6455 extends Test\Integration\Suite
);
}
- protected function _case_send_fragmented_text_frame_of_1_bytes_with_a_valid_UTF_8_payload($payload)
+ protected function _case_send_fragmented_text_frame_of_1_bytes_with_a_valid_UTF_8_payload($payload): void
{
$this
->given(
@@ -425,7 +426,7 @@ class Rfc6455 extends Test\Integration\Suite
$onCloseCalled
)
)
- ->when(function () use ($client, $payload) {
+ ->when(function () use ($client, $payload): void {
$bytes = str_split($payload);
$firstByte = array_shift($bytes);
$lastByte = array_pop($bytes);
@@ -449,7 +450,7 @@ class Rfc6455 extends Test\Integration\Suite
->isTrue();
}
- public function case_send_a_message_and_close()
+ public function case_send_a_message_and_close(): void
{
$this
->given(
@@ -524,7 +525,7 @@ class Rfc6455 extends Test\Integration\Suite
: (Websocket\Connection::OPCODE_PING === $opcode
? 'ping'
: 'message'),
- function (Event\Bucket $bucket) use (&$calledA, $self, $expectedMessage) {
+ function (Event\Bucket $bucket) use (&$calledA, $self, $expectedMessage): void {
$calledA = true;
$self
@@ -536,7 +537,7 @@ class Rfc6455 extends Test\Integration\Suite
);
$client->on(
'close',
- function (Event\Bucket $bucket) use (&$calledB, $self, $expectedCloseCode) {
+ function (Event\Bucket $bucket) use (&$calledB, $self, $expectedCloseCode): void {
$calledB = true;
$self
@@ -548,7 +549,7 @@ class Rfc6455 extends Test\Integration\Suite
);
$client->on(
'error',
- function (Event\Bucket $bucket) use ($self) {
+ function (Event\Bucket $bucket) use ($self): void {
$self
->boolean(true)
->isFalse();
@@ -586,7 +587,6 @@ class Rfc6455 extends Test\Integration\Suite
*
* An exception that is thrown to stop the server and exits gently.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class StopServerException extends \RuntimeException
diff --git a/Test/Unit/Client.php b/Test/Unit/Client.php
index d526c61..6b6cfeb 100644
--- a/Test/Unit/Client.php
+++ b/Test/Unit/Client.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -48,12 +50,11 @@ use Mock\Hoa\Socket;
*
* Test suite for the WebSocket client class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Client extends Test\Unit\Suite
{
- public function case_is_a_connection()
+ public function case_is_a_connection(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -63,7 +64,7 @@ class Client extends Test\Unit\Suite
->isInstanceOf(Websocket\Connection::class);
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -81,7 +82,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($response);
}
- public function case_constructor_with_an_undefined_endpoint()
+ public function case_constructor_with_an_undefined_endpoint(): void
{
$this
->given(
@@ -99,7 +100,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($response);
}
- public function case_constructor_with_a_socket_defined_endpoint()
+ public function case_constructor_with_a_socket_defined_endpoint(): void
{
$this
->given(
@@ -120,7 +121,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($response);
}
- public function case_constructor_with_an_undefined_response()
+ public function case_constructor_with_an_undefined_response(): void
{
$this
->given(
@@ -137,7 +138,7 @@ class Client extends Test\Unit\Suite
->isInstanceOf(Http\Response::class);
}
- public function case_connect()
+ public function case_connect(): void
{
$this
->given(
@@ -145,7 +146,7 @@ class Client extends Test\Unit\Suite
$this->mockGenerator->makeVisible('doHandshake')->generate(SUT::class),
$client = new \Mock\Hoa\Websocket\Client($socket),
- $this->calling($client)->doHandshake = function () use (&$called) {
+ $this->calling($client)->doHandshake = function () use (&$called): void {
$called = true;
return;
@@ -159,7 +160,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_receive_a_complete_message_and_is_not_disconnected()
+ public function case_receive_a_complete_message_and_is_not_disconnected(): void
{
$self = $this;
@@ -175,7 +176,7 @@ class Client extends Test\Unit\Suite
$this->calling($socket)->getCurrentNode = $node,
$this->calling($socket)->isDisconnected = false,
- $this->calling($client)->_run = function (Websocket\Node $_node) use (&$called, $self, $node) {
+ $this->calling($client)->_run = function (Websocket\Node $_node) use (&$called, $self, $node): void {
$called = true;
$self
@@ -193,7 +194,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_receive_an_incomplete_message_and_is_disconnected()
+ public function case_receive_an_incomplete_message_and_is_disconnected(): void
{
$self = $this;
@@ -209,7 +210,7 @@ class Client extends Test\Unit\Suite
$this->calling($socket)->getCurrentNode = $node,
$this->calling($socket)->isDisconnected = true,
- $this->calling($client)->_run = function (Websocket\Node $_node) use (&$called, $self, $node) {
+ $this->calling($client)->_run = function (Websocket\Node $_node) use (&$called, $self, $node): void {
$called = true;
$self
@@ -227,7 +228,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_do_handshake()
+ public function case_do_handshake(): void
{
$self = $this;
@@ -298,7 +299,7 @@ class Client extends Test\Unit\Suite
$this->calling($client)->getNewChallenge = $challenge,
$client->on(
'open',
- function (Event\Bucket $bucket) use (&$calledE, $self) {
+ function (Event\Bucket $bucket) use (&$calledE, $self): void {
$calledE = true;
$self
@@ -339,7 +340,7 @@ class Client extends Test\Unit\Suite
]);
}
- public function case_do_handshake_with_a_secured_connection()
+ public function case_do_handshake_with_a_secured_connection(): void
{
$self = $this;
@@ -423,7 +424,7 @@ class Client extends Test\Unit\Suite
$this->calling($client)->getNewChallenge = $challenge,
$client->on(
'open',
- function (Event\Bucket $bucket) use (&$calledF, $self) {
+ function (Event\Bucket $bucket) use (&$calledF, $self): void {
$calledF = true;
$self
@@ -466,7 +467,7 @@ class Client extends Test\Unit\Suite
]);
}
- public function case_do_handshake_with_no_host()
+ public function case_do_handshake_with_no_host(): void
{
$self = $this;
@@ -487,7 +488,7 @@ class Client extends Test\Unit\Suite
$this->calling($socket)->enableEncryption = null,
$this->calling($socket)->setStreamBlocking = null
)
- ->exception(function () use ($client) {
+ ->exception(function () use ($client): void {
$this->invoke($client)->doHandshake();
})
->isInstanceOf(Websocket\Exception::class);
@@ -528,7 +529,7 @@ class Client extends Test\Unit\Suite
);
}
- protected function _case_do_handshake_invalid_response($response)
+ protected function _case_do_handshake_invalid_response($response): void
{
$self = $this;
@@ -592,20 +593,20 @@ class Client extends Test\Unit\Suite
},
$this->calling($client)->getNewChallenge = $challenge
)
- ->exception(function () use ($client) {
+ ->exception(function () use ($client): void {
$this->invoke($client)->doHandshake();
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_get_new_challenge()
+ public function case_get_new_challenge(): void
{
$this
->given(
$this->mockGenerator->orphanize('__construct'),
$client = new \Mock\Hoa\Websocket\Client()
)
- ->when(function () use ($client) {
+ ->when(function () use ($client): void {
for ($i = 0; $i < 1000; ++$i) {
$this
->string($client->getNewChallenge())
@@ -624,7 +625,7 @@ class Client extends Test\Unit\Suite
return $this->_case_close(null);
}
- protected function _case_close($protocolCalledValue)
+ protected function _case_close($protocolCalledValue): void
{
$self = $this;
@@ -643,7 +644,7 @@ class Client extends Test\Unit\Suite
$this->calling($node)->getProtocolImplementation = $protocolCalledValue ? $protocol : null,
- $this->calling($protocol)->close = function ($_code, $_reason, $_mask) use (&$calledA, $self, $code, $reason, $mask) {
+ $this->calling($protocol)->close = function ($_code, $_reason, $_mask) use (&$calledA, $self, $code, $reason, $mask): void {
$calledA = true;
$self
@@ -658,7 +659,7 @@ class Client extends Test\Unit\Suite
},
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($socket)->mute = function () use (&$calledB) {
+ $this->calling($socket)->mute = function () use (&$calledB): void {
$calledB = true;
return;
@@ -700,7 +701,7 @@ class Client extends Test\Unit\Suite
->isTrue();
}
- public function case_set_end_point()
+ public function case_set_end_point(): void
{
$this
->given(
@@ -714,7 +715,7 @@ class Client extends Test\Unit\Suite
->isEqualTo($endPoint);
}
- public function case_get_end_point()
+ public function case_get_end_point(): void
{
$this
->given(
@@ -729,7 +730,7 @@ class Client extends Test\Unit\Suite
->isEqualTo($endPoint);
}
- public function case_set_response()
+ public function case_set_response(): void
{
$this
->given(
@@ -744,7 +745,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($response);
}
- public function case_get_response()
+ public function case_get_response(): void
{
$this
->given(
@@ -760,7 +761,7 @@ class Client extends Test\Unit\Suite
->isIdenticalTo($response);
}
- public function case_set_host()
+ public function case_set_host(): void
{
$this
->given(
@@ -773,7 +774,7 @@ class Client extends Test\Unit\Suite
->isNull();
}
- public function case_get_host()
+ public function case_get_host(): void
{
$this
->given(
@@ -788,7 +789,7 @@ class Client extends Test\Unit\Suite
->isEqualTo($host);
}
- public function case_get_an_undefined_host()
+ public function case_get_an_undefined_host(): void
{
unset($_SERVER);
@@ -803,7 +804,7 @@ class Client extends Test\Unit\Suite
->isNull();
}
- public function case_get_a_global_defined_host()
+ public function case_get_a_global_defined_host(): void
{
$this
->given(
diff --git a/Test/Unit/Connection.php b/Test/Unit/Connection.php
index 64a1e4a..7643250 100644
--- a/Test/Unit/Connection.php
+++ b/Test/Unit/Connection.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -47,12 +49,11 @@ use Mock\Hoa\Websocket\Connection as SUT;
*
* Test suite for the WebSocket connection class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Connection extends Test\Unit\Suite
{
- public function case_opcodes()
+ public function case_opcodes(): void
{
$this
->then
@@ -70,7 +71,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(0xa);
}
- public function case_close_codes()
+ public function case_close_codes(): void
{
$this
->then
@@ -100,7 +101,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(1015);
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given($socket = new Socket\Client('tcp://*:1234'))
@@ -129,7 +130,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_do_handshake()
+ public function case_run_do_handshake(): void
{
$self = $this;
@@ -142,7 +143,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
'open',
- function (Event\Bucket $bucket) use (&$calledA, $self) {
+ function (Event\Bucket $bucket) use (&$calledA, $self): void {
$calledA = true;
$self
@@ -154,7 +155,7 @@ class Connection extends Test\Unit\Suite
),
$this->calling($node)->getHandshake = FAILED,
- $this->calling($connection)->doHandshake = function () use (&$calledB) {
+ $this->calling($connection)->doHandshake = function () use (&$calledB): void {
$calledB = true;
return;
@@ -170,7 +171,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_cannot_read_the_frame()
+ public function case_run_cannot_read_the_frame(): void
{
$self = $this;
@@ -197,7 +198,7 @@ class Connection extends Test\Unit\Suite
),
$this->calling($socket)->getCurrentNode = $node,
$this->calling($node)->getHandshake = SUCCEED,
- $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self): void {
$called = true;
$self
@@ -217,7 +218,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_client_messages_must_be_masked()
+ public function case_run_client_messages_must_be_masked(): void
{
$self = $this;
@@ -241,7 +242,7 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self): void {
$called = true;
$self
@@ -261,7 +262,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_ping_opcode()
+ public function case_run_ping_opcode(): void
{
$self = $this;
@@ -285,7 +286,7 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA, $self) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA, $self): void {
$calledA = true;
$self
@@ -301,7 +302,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
'ping',
- function (Event\Bucket $bucket) use (&$calledB, $self) {
+ function (Event\Bucket $bucket) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -352,7 +353,7 @@ class Connection extends Test\Unit\Suite
]);
}
- protected function _case_run_ping_opcode_with_invalid_frame(array $frame)
+ protected function _case_run_ping_opcode_with_invalid_frame(array $frame): void
{
$self = $this;
@@ -367,12 +368,12 @@ class Connection extends Test\Unit\Suite
$this->calling($node)->getHandshake = SUCCEED,
$this->calling($protocol)->readFrame = $frame,
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -386,7 +387,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
'ping',
- function (Event\Bucket $bucket) use (&$calledC) {
+ function (Event\Bucket $bucket) use (&$calledC): void {
$calledC = true;
return;
@@ -405,7 +406,7 @@ class Connection extends Test\Unit\Suite
->isNull();
}
- public function case_run_pong_opcode()
+ public function case_run_pong_opcode(): void
{
$this
->given(
@@ -427,7 +428,7 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$called) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$called): void {
$called = true;
return;
@@ -441,7 +442,7 @@ class Connection extends Test\Unit\Suite
->isNull();
}
- public function case_run_pong_opcode_not_fin()
+ public function case_run_pong_opcode_not_fin(): void
{
$self = $this;
@@ -465,12 +466,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -502,7 +503,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_x_frame_opcode_with_fragments(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_x_frame_opcode_with_fragments($opcode)
+ protected function _case_run_x_frame_opcode_with_fragments($opcode): void
{
$self = $this;
@@ -527,12 +528,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -554,7 +555,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_text_frame_opcode_with_invalid_message_encoding()
+ public function case_run_text_frame_opcode_with_invalid_message_encoding(): void
{
$self = $this;
@@ -578,12 +579,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => iconv('UTF-8', 'UTF-16', '😄')
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -615,7 +616,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_x_frame_opcode(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_x_frame_opcode($opcode)
+ protected function _case_run_x_frame_opcode($opcode): void
{
$self = $this;
@@ -639,12 +640,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB): void {
$calledB = true;
return;
@@ -652,7 +653,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
SUT::OPCODE_TEXT_FRAME === $opcode ? 'message' : 'binary-message',
- function (Event\Bucket $bucket) use (&$calledC, $self) {
+ function (Event\Bucket $bucket) use (&$calledC, $self): void {
$calledC = true;
$self
@@ -687,7 +688,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_x_frame_opcode_with_an_exception_from_the_listener(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_x_frame_opcode_with_an_exception_from_the_listener($opcode)
+ protected function _case_run_x_frame_opcode_with_an_exception_from_the_listener($opcode): void
{
$self = $this;
@@ -711,12 +712,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB): void {
$calledB = true;
return;
@@ -724,7 +725,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
SUT::OPCODE_TEXT_FRAME === $opcode ? 'message' : 'binary-message',
- function (Event\Bucket $bucket) use (&$calledC, $self) {
+ function (Event\Bucket $bucket) use (&$calledC, $self): void {
$calledC = true;
$self
@@ -738,7 +739,7 @@ class Connection extends Test\Unit\Suite
),
$connection->on(
'error',
- function (Event\Bucket $bucket) use (&$calledD, $self) {
+ function (Event\Bucket $bucket) use (&$calledD, $self): void {
$calledD = true;
$self
@@ -778,7 +779,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_incomplete_x_frame_opcode(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_incomplete_x_frame_opcode($opcode)
+ protected function _case_run_incomplete_x_frame_opcode($opcode): void
{
$this
->given(
@@ -800,12 +801,12 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_mask) use (&$calledA): void {
$calledA = true;
return;
},
- $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$calledB): void {
$calledB = true;
return;
@@ -813,7 +814,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
'message',
- function (Event\Bucket $bucket) use (&$calledC) {
+ function (Event\Bucket $bucket) use (&$calledC): void {
$calledC = true;
return;
@@ -840,7 +841,7 @@ class Connection extends Test\Unit\Suite
->isEqualTo(SUT::OPCODE_BINARY_FRAME === $opcode);
}
- public function case_run_continuation_frame_opcode_with_fragments()
+ public function case_run_continuation_frame_opcode_with_fragments(): void
{
$self = $this;
@@ -865,7 +866,7 @@ class Connection extends Test\Unit\Suite
'length' => 6,
'message' => 'foobar'
],
- $this->calling($connection)->close = function ($_code, $_reason) use (&$called) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$called): void {
$called = true;
$self
@@ -895,7 +896,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_x_frame_and_continuation_frame_opcodes(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_x_frame_and_continuation_frame_opcodes($opcode)
+ protected function _case_run_x_frame_and_continuation_frame_opcodes($opcode): void
{
$self = $this;
@@ -943,7 +944,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
SUT::OPCODE_TEXT_FRAME === $opcode ? 'message' : 'binary-message',
- function (Event\Bucket $bucket) use (&$called, $self) {
+ function (Event\Bucket $bucket) use (&$called, $self): void {
$called = true;
$self
@@ -1000,7 +1001,7 @@ class Connection extends Test\Unit\Suite
return $this->_case_run_x_frame_and_continuation_frame_opcodes_with_an_exception_from_the_listener(SUT::OPCODE_BINARY_FRAME);
}
- protected function _case_run_x_frame_and_continuation_frame_opcodes_with_an_exception_from_the_listener($opcode)
+ protected function _case_run_x_frame_and_continuation_frame_opcodes_with_an_exception_from_the_listener($opcode): void
{
$self = $this;
@@ -1048,7 +1049,7 @@ class Connection extends Test\Unit\Suite
$connection->on(
SUT::OPCODE_TEXT_FRAME === $opcode ? 'message' : 'binary-message',
- function (Event\Bucket $bucket) use (&$calledA, $self) {
+ function (Event\Bucket $bucket) use (&$calledA, $self): void {
$calledA = true;
$self
@@ -1062,7 +1063,7 @@ class Connection extends Test\Unit\Suite
),
$connection->on(
'error',
- function (Event\Bucket $bucket) use (&$calledB, $self) {
+ function (Event\Bucket $bucket) use (&$calledB, $self): void {
$calledB = true;
$self
@@ -1118,7 +1119,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_run_text_frame_and_continuation_frame_opcodes_with_invalid_message_encoding()
+ public function case_run_text_frame_and_continuation_frame_opcodes_with_invalid_message_encoding(): void
{
$self = $this;
@@ -1154,7 +1155,7 @@ class Connection extends Test\Unit\Suite
],
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self) {
+ $this->calling($connection)->close = function ($_code, $_reason) use (&$called, $self): void {
$called = true;
$self
@@ -1189,7 +1190,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case__send()
+ public function case__send(): void
{
$self = $this;
@@ -1238,7 +1239,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case__send_with_no_handshake()
+ public function case__send_with_no_handshake(): void
{
$this
->given(
@@ -1274,7 +1275,7 @@ class Connection extends Test\Unit\Suite
->isNull();
}
- public function case_close_with_no_protocol()
+ public function case_close_with_no_protocol(): void
{
$this
->given(
@@ -1294,7 +1295,7 @@ class Connection extends Test\Unit\Suite
->isTrue();
}
- public function case_close()
+ public function case_close(): void
{
$self = $this;
@@ -1310,7 +1311,7 @@ class Connection extends Test\Unit\Suite
$code = SUT::CLOSE_DATA_ERROR,
$reason = 'foo',
- $this->calling($protocol)->close = function ($_code, $_reason) use (&$called, $self, $code, $reason) {
+ $this->calling($protocol)->close = function ($_code, $_reason) use (&$called, $self, $code, $reason): void {
$called = true;
$self
diff --git a/Test/Unit/Exception/BadProtocol.php b/Test/Unit/Exception/BadProtocol.php
index 1c976cc..e9eaa30 100644
--- a/Test/Unit/Exception/BadProtocol.php
+++ b/Test/Unit/Exception/BadProtocol.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Websocket\Exception\BadProtocol as SUT;
*
* Test suite of the bad protocol exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class BadProtocol extends Test\Unit\Suite
{
- public function case_hoa_websocket_exception()
+ public function case_hoa_websocket_exception(): void
{
$this
->when($result = new SUT('foo', 0))
diff --git a/Test/Unit/Exception/CloseError.php b/Test/Unit/Exception/CloseError.php
index d98d426..789db25 100644
--- a/Test/Unit/Exception/CloseError.php
+++ b/Test/Unit/Exception/CloseError.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Websocket\Exception\CloseError as SUT;
*
* Test suite of the close error exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class CloseError extends Test\Unit\Suite
{
- public function case_hoa_websocket_exception()
+ public function case_hoa_websocket_exception(): void
{
$this
->when($result = new SUT('foo', 0))
@@ -59,7 +60,7 @@ class CloseError extends Test\Unit\Suite
->isInstanceOf(Websocket\Exception::class);
}
- public function case_set_error_code()
+ public function case_set_error_code(): void
{
$this
->given($exception = new SUT('foo', 0))
@@ -69,7 +70,7 @@ class CloseError extends Test\Unit\Suite
->isNull();
}
- public function case_get_error_code()
+ public function case_get_error_code(): void
{
$this
->given(
diff --git a/Test/Unit/Exception/Exception.php b/Test/Unit/Exception/Exception.php
index 77fd3c4..08ba585 100644
--- a/Test/Unit/Exception/Exception.php
+++ b/Test/Unit/Exception/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Websocket\Exception as SUT;
*
* Test suite of the exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends Test\Unit\Suite
{
- public function case_hoa_exception()
+ public function case_hoa_exception(): void
{
$this
->when($result = new SUT('foo', 0))
diff --git a/Test/Unit/Exception/InvalidMessage.php b/Test/Unit/Exception/InvalidMessage.php
index 4e9b08f..c715ca8 100644
--- a/Test/Unit/Exception/InvalidMessage.php
+++ b/Test/Unit/Exception/InvalidMessage.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Websocket\Exception\InvalidMessage as SUT;
*
* Test suite of the bad protocol exception.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class InvalidMessage extends Test\Unit\Suite
{
- public function case_hoa_websocket_exception()
+ public function case_hoa_websocket_exception(): void
{
$this
->when($result = new SUT('foo', 0))
diff --git a/Test/Unit/Node.php b/Test/Unit/Node.php
index c7680d3..5b83129 100644
--- a/Test/Unit/Node.php
+++ b/Test/Unit/Node.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Mock\Hoa\Websocket\Node as SUT;
*
* Test suite for the node class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Node extends Test\Unit\Suite
{
- public function case_is_a_node()
+ public function case_is_a_node(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -60,7 +61,7 @@ class Node extends Test\Unit\Suite
->isInstanceOf(HoaSocket\Node::class);
}
- public function case_set_protocol_implementation()
+ public function case_set_protocol_implementation(): void
{
$this
->given(
@@ -84,7 +85,7 @@ class Node extends Test\Unit\Suite
->isIdenticalTo($protocolA);
}
- public function case_get_protocol_implementation()
+ public function case_get_protocol_implementation(): void
{
$this
->given(
@@ -100,7 +101,7 @@ class Node extends Test\Unit\Suite
->isIdenticalTo($protocol);
}
- public function case_set_handshake()
+ public function case_set_handshake(): void
{
$this
->given(
@@ -118,7 +119,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_get_handshake()
+ public function case_get_handshake(): void
{
$this
->given(
@@ -132,7 +133,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_append_message_fragment()
+ public function case_append_message_fragment(): void
{
$this
->given(
@@ -145,7 +146,7 @@ class Node extends Test\Unit\Suite
->isEqualTo('foo');
}
- public function case_append_many_message_fragments()
+ public function case_append_many_message_fragments(): void
{
$this
->given(
@@ -171,7 +172,7 @@ class Node extends Test\Unit\Suite
->isEqualTo($fragmentA . $fragmentB . $fragmentC);
}
- public function case_get_fragmented_message()
+ public function case_get_fragmented_message(): void
{
$this
->given(
@@ -190,7 +191,7 @@ class Node extends Test\Unit\Suite
->isEqualTo($fragmentA . $fragmentB . $fragmentC);
}
- public function case_get_number_of_fragments_for_an_message()
+ public function case_get_number_of_fragments_for_an_message(): void
{
$this
->given(
@@ -203,7 +204,7 @@ class Node extends Test\Unit\Suite
->isEqualTo(0);
}
- public function case_get_number_of_fragments()
+ public function case_get_number_of_fragments(): void
{
$this
->given(
@@ -222,7 +223,7 @@ class Node extends Test\Unit\Suite
->isEqualTo(3);
}
- public function case_set_complete()
+ public function case_set_complete(): void
{
$this
->given(
@@ -240,7 +241,7 @@ class Node extends Test\Unit\Suite
->isFalse();
}
- public function case_is_message_complete()
+ public function case_is_message_complete(): void
{
$this
->given(
@@ -254,7 +255,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_is_message_not_complete()
+ public function case_is_message_not_complete(): void
{
$this
->given(
@@ -268,7 +269,7 @@ class Node extends Test\Unit\Suite
->isFalse();
}
- public function case_message_is_complete_by_default()
+ public function case_message_is_complete_by_default(): void
{
$this
->given(
@@ -281,7 +282,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_set_binary()
+ public function case_set_binary(): void
{
$this
->given(
@@ -299,7 +300,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_is_binary()
+ public function case_is_binary(): void
{
$this
->given(
@@ -313,7 +314,7 @@ class Node extends Test\Unit\Suite
->isTrue();
}
- public function case_is_not_binary()
+ public function case_is_not_binary(): void
{
$this
->given(
@@ -327,7 +328,7 @@ class Node extends Test\Unit\Suite
->isFalse();
}
- public function case_not_binary_by_default()
+ public function case_not_binary_by_default(): void
{
$this
->given(
@@ -340,7 +341,7 @@ class Node extends Test\Unit\Suite
->isFalse();
}
- public function case_clear_fragmentation()
+ public function case_clear_fragmentation(): void
{
$this
->given(
diff --git a/Test/Unit/Protocol/Generic.php b/Test/Unit/Protocol/Generic.php
index a0e5fec..bcd8372 100644
--- a/Test/Unit/Protocol/Generic.php
+++ b/Test/Unit/Protocol/Generic.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Mock\Hoa\Websocket\Protocol\Generic as SUT;
*
* Test suite for the generic protocol class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Generic extends Test\Unit\Suite
{
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given($socket = new Socket\Server('tcp://*:1234'))
diff --git a/Test/Unit/Protocol/Hybi00.php b/Test/Unit/Protocol/Hybi00.php
index 9ff9283..e5b0661 100644
--- a/Test/Unit/Protocol/Hybi00.php
+++ b/Test/Unit/Protocol/Hybi00.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -47,12 +49,11 @@ use Mock\Hoa\Websocket\Protocol\Hybi00 as SUT;
*
* Test suite for the Hybi00 protocol implementation.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Hybi00 extends Test\Unit\Suite
{
- public function case_extends_generic()
+ public function case_extends_generic(): void
{
$this
->given($socket = new Socket\Server('tcp://*:1234'))
@@ -62,7 +63,7 @@ class Hybi00 extends Test\Unit\Suite
->isInstanceOf(Websocket\Protocol\Generic::class);
}
- public function case_do_handshake_illegal_sec_websocket_key_header()
+ public function case_do_handshake_illegal_sec_websocket_key_header(): void
{
$this
->given(
@@ -70,13 +71,13 @@ class Hybi00 extends Test\Unit\Suite
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket)
)
- ->exception(function () use ($protocol, $request) {
+ ->exception(function () use ($protocol, $request): void {
$protocol->doHandshake($request);
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_do_handshake()
+ public function case_do_handshake(): void
{
$self = $this;
@@ -102,7 +103,7 @@ class Hybi00 extends Test\Unit\Suite
),
$this->calling($socket)->getCurrentNode = $node,
- $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self) {
+ $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self): void {
$calledA = true;
$self
@@ -111,7 +112,7 @@ class Hybi00 extends Test\Unit\Suite
return;
},
- $this->calling($socket)->writeAll = function ($data) use (&$calledB, $self, $challenge) {
+ $this->calling($socket)->writeAll = function ($data) use (&$calledB, $self, $challenge): void {
$calledB = true;
$self
@@ -138,7 +139,7 @@ class Hybi00 extends Test\Unit\Suite
->isTrue();
}
- public function case_read_empty_frame()
+ public function case_read_empty_frame(): void
{
$this
->given(
@@ -162,7 +163,7 @@ class Hybi00 extends Test\Unit\Suite
]);
}
- public function case_read_frame()
+ public function case_read_frame(): void
{
$this
->given(
@@ -188,7 +189,7 @@ class Hybi00 extends Test\Unit\Suite
]);
}
- public function case_write_frame()
+ public function case_write_frame(): void
{
$self = $this;
@@ -220,7 +221,7 @@ class Hybi00 extends Test\Unit\Suite
->isTrue();
}
- public function case_send()
+ public function case_send(): void
{
$self = $this;
@@ -234,7 +235,7 @@ class Hybi00 extends Test\Unit\Suite
$end = false,
$mask = true,
- $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $message) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $message): void {
$called = true;
$self
@@ -258,14 +259,14 @@ class Hybi00 extends Test\Unit\Suite
->isTrue();
}
- public function case_close()
+ public function case_close(): void
{
$this
->given(
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket),
- $this->calling($socket)->write = function () use (&$called) {
+ $this->calling($socket)->write = function () use (&$called): void {
$called = true;
}
)
diff --git a/Test/Unit/Protocol/Rfc6455.php b/Test/Unit/Protocol/Rfc6455.php
index e2ab439..0d24d53 100644
--- a/Test/Unit/Protocol/Rfc6455.php
+++ b/Test/Unit/Protocol/Rfc6455.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -47,12 +49,11 @@ use Mock\Hoa\Websocket\Protocol\Rfc6455 as SUT;
*
* Test suite for the RFC6455 protocol implementation.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Rfc6455 extends Test\Unit\Suite
{
- public function case_guid()
+ public function case_guid(): void
{
$this
->when($result = SUT::GUID)
@@ -61,7 +62,7 @@ class Rfc6455 extends Test\Unit\Suite
->isEqualTo('258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
}
- public function case_extends_generic()
+ public function case_extends_generic(): void
{
$this
->given($socket = new Socket\Server('tcp://*:1234'))
@@ -71,7 +72,7 @@ class Rfc6455 extends Test\Unit\Suite
->isInstanceOf(Websocket\Protocol\Generic::class);
}
- public function case_do_handshake_missing_sec_websocket_key_header()
+ public function case_do_handshake_missing_sec_websocket_key_header(): void
{
$this
->given(
@@ -79,13 +80,13 @@ class Rfc6455 extends Test\Unit\Suite
$socket = new Socket\Server('tcp://*:1234'),
$protocol = new SUT($socket)
)
- ->exception(function () use ($protocol, $request) {
+ ->exception(function () use ($protocol, $request): void {
$protocol->doHandshake($request);
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_do_handshake_illegal_sec_websocket_key_header_invalid_encoding()
+ public function case_do_handshake_illegal_sec_websocket_key_header_invalid_encoding(): void
{
$this
->given(
@@ -95,13 +96,13 @@ class Rfc6455 extends Test\Unit\Suite
$request['sec-websocket-key'] = 'invalid'
)
- ->exception(function () use ($protocol, $request) {
+ ->exception(function () use ($protocol, $request): void {
$protocol->doHandshake($request);
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_do_handshake_illegal_sec_websocket_key_header_invalid_length()
+ public function case_do_handshake_illegal_sec_websocket_key_header_invalid_length(): void
{
$this
->given(
@@ -111,13 +112,13 @@ class Rfc6455 extends Test\Unit\Suite
$request['sec-websocket-key'] = base64_encode('invalid')
)
- ->exception(function () use ($protocol, $request) {
+ ->exception(function () use ($protocol, $request): void {
$protocol->doHandshake($request);
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_do_handshake()
+ public function case_do_handshake(): void
{
$self = $this;
@@ -133,7 +134,7 @@ 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) {
+ $this->calling($node)->setHandshake = function ($handshake) use (&$calledA, $self): void {
$calledA = true;
$self
@@ -142,7 +143,7 @@ class Rfc6455 extends Test\Unit\Suite
return;
},
- $this->calling($socket)->writeAll = function ($_data) use (&$calledB, $self, $challenge) {
+ $this->calling($socket)->writeAll = function ($_data) use (&$calledB, $self, $challenge): void {
$calledB = true;
$self
@@ -168,7 +169,7 @@ class Rfc6455 extends Test\Unit\Suite
->isTrue();
}
- public function case_read_frame_no_opcode()
+ public function case_read_frame_no_opcode(): void
{
$this
->given(
@@ -200,7 +201,7 @@ class Rfc6455 extends Test\Unit\Suite
return $this->_case_read_frame_rsvX_is_not_equal_to_0(0x0, 0x0, 0x1);
}
- protected function _case_read_frame_rsvX_is_not_equal_to_0($rsv1, $rsv2, $rsv3)
+ protected function _case_read_frame_rsvX_is_not_equal_to_0($rsv1, $rsv2, $rsv3): void
{
$this
->given(
@@ -209,7 +210,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- (0x1 << 7)
+ (0x1 << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -221,7 +222,7 @@ class Rfc6455 extends Test\Unit\Suite
| 42
)
)
- ->exception(function () use ($protocol) {
+ ->exception(function () use ($protocol): void {
$protocol->readFrame();
})
->isInstanceOf(Websocket\Exception\CloseError::class)
@@ -229,7 +230,7 @@ class Rfc6455 extends Test\Unit\Suite
->isEqualTo(Websocket\Connection::CLOSE_PROTOCOL_ERROR);
}
- public function case_read_frame_of_length_0()
+ public function case_read_frame_of_length_0(): void
{
$this
->given(
@@ -246,7 +247,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -281,7 +282,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- protected function _case_read_frame_of_small_length($opcode, $fin)
+ protected function _case_read_frame_of_small_length($opcode, $fin): void
{
$this
->given(
@@ -296,7 +297,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -326,7 +327,7 @@ class Rfc6455 extends Test\Unit\Suite
]);
}
- public function case_read_frame_of_medium_length()
+ public function case_read_frame_of_medium_length(): void
{
$this
->given(
@@ -343,7 +344,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -374,7 +375,7 @@ class Rfc6455 extends Test\Unit\Suite
]);
}
- public function case_read_frame_of_long_length()
+ public function case_read_frame_of_long_length(): void
{
$this
->given(
@@ -391,7 +392,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -430,7 +431,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_read_masked_frame_of_length_0()
+ public function case_read_masked_frame_of_length_0(): void
{
$this
->given(
@@ -447,7 +448,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -475,7 +476,7 @@ class Rfc6455 extends Test\Unit\Suite
]);
}
- public function case_read_masked_frame_of_small_length()
+ public function case_read_masked_frame_of_small_length(): void
{
$self = $this;
@@ -496,7 +497,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -535,7 +536,7 @@ class Rfc6455 extends Test\Unit\Suite
]);
}
- public function case_read_masked_frame_of_medium_length()
+ public function case_read_masked_frame_of_medium_length(): void
{
$self = $this;
@@ -556,7 +557,7 @@ class Rfc6455 extends Test\Unit\Suite
$this->calling($socket)->read[1] =
chr(
- ($fin << 7)
+ ($fin << 7)
| ($rsv1 << 6)
| ($rsv2 << 5)
| ($rsv3 << 4)
@@ -596,7 +597,7 @@ class Rfc6455 extends Test\Unit\Suite
]);
}
- public function case_write_frame_of_length_0()
+ public function case_write_frame_of_length_0(): void
{
$this
->given(
@@ -604,7 +605,7 @@ class Rfc6455 extends Test\Unit\Suite
$protocol = new SUT($socket),
$message = '',
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -639,7 +640,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- protected function _case_write_frame_of_small_length($opcode, $fin)
+ protected function _case_write_frame_of_small_length($opcode, $fin): void
{
$this
->given(
@@ -647,7 +648,7 @@ class Rfc6455 extends Test\Unit\Suite
$protocol = new SUT($socket),
$message = str_repeat('a', 0x7d),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -661,9 +662,9 @@ class Rfc6455 extends Test\Unit\Suite
->isEqualTo(
chr(
($fin << 7)
- | (0x0 << 6)
- | (0x0 << 5)
- | (0x0 << 4)
+ | (0x0 << 6)
+ | (0x0 << 5)
+ | (0x0 << 4)
| $opcode
) .
chr(
@@ -674,7 +675,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_write_frame_of_medium_length()
+ public function case_write_frame_of_medium_length(): void
{
$this
->given(
@@ -682,7 +683,7 @@ class Rfc6455 extends Test\Unit\Suite
$protocol = new SUT($socket),
$message = str_repeat('a', 0x7e),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -710,7 +711,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_write_frame_of_long_length()
+ public function case_write_frame_of_long_length(): void
{
$this
->given(
@@ -718,7 +719,7 @@ class Rfc6455 extends Test\Unit\Suite
$protocol = new SUT($socket),
$message = str_repeat('a', 0x10000),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -764,7 +765,7 @@ class Rfc6455 extends Test\Unit\Suite
return $this->_case_write_masked_frame_of_small_length(str_repeat('a', 0x7d));
}
- protected function _case_write_masked_frame_of_small_length($message)
+ protected function _case_write_masked_frame_of_small_length($message): void
{
$this
->given(
@@ -778,7 +779,7 @@ class Rfc6455 extends Test\Unit\Suite
$maskingKey
),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -810,7 +811,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_write_masked_frame_of_medium_length()
+ public function case_write_masked_frame_of_medium_length(): void
{
$this
->given(
@@ -824,7 +825,7 @@ class Rfc6455 extends Test\Unit\Suite
$maskingKey
),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -857,7 +858,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_write_masked_frame_of_long_length()
+ public function case_write_masked_frame_of_long_length(): void
{
$this
->given(
@@ -871,7 +872,7 @@ class Rfc6455 extends Test\Unit\Suite
$maskingKey
),
- $this->calling($socket)->writeAll = function ($data) use (&$output) {
+ $this->calling($socket)->writeAll = function ($data) use (&$output): void {
$output = $data;
return;
@@ -904,7 +905,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- public function case_get_masking_key()
+ public function case_get_masking_key(): void
{
$this
->given(
@@ -981,7 +982,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- protected function _case_send_invalid_message($opcode)
+ protected function _case_send_invalid_message($opcode): void
{
$this
->given(
@@ -989,7 +990,7 @@ class Rfc6455 extends Test\Unit\Suite
$protocol = new SUT($socket),
$message = iconv('UTF-8', 'UTF-16', '😄')
)
- ->exception(function () use ($protocol, $message) {
+ ->exception(function () use ($protocol, $message): void {
$protocol->send($message);
})
->isInstanceOf(Websocket\Exception\InvalidMessage::class);
@@ -1005,7 +1006,7 @@ class Rfc6455 extends Test\Unit\Suite
);
}
- protected function _case_send($message, $opcode, $end, $mask)
+ protected function _case_send($message, $opcode, $end, $mask): void
{
$self = $this;
@@ -1014,7 +1015,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, $message, $opcode, $end, $mask) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $message, $opcode, $end, $mask): void {
$called = true;
$self
@@ -1070,7 +1071,7 @@ class Rfc6455 extends Test\Unit\Suite
return $this->_case_close($closeType, 'foobar', true);
}
- protected function _case_close($code, $reason, $mask)
+ protected function _case_close($code, $reason, $mask): void
{
$self = $this;
@@ -1079,7 +1080,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) {
+ $this->calling($protocol)->writeFrame = function ($_message, $_opcode, $_end, $_mask) use (&$called, $self, $code, $reason, $mask): void {
$called = true;
$self
diff --git a/Test/Unit/Server.php b/Test/Unit/Server.php
index 961116d..c759cdb 100644
--- a/Test/Unit/Server.php
+++ b/Test/Unit/Server.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -47,12 +49,11 @@ use Mock\Hoa\Socket;
*
* Test suite for the WebSocket server class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Server extends Test\Unit\Suite
{
- public function case_is_a_connection()
+ public function case_is_a_connection(): void
{
$this
->given($this->mockGenerator->orphanize('__construct'))
@@ -62,7 +63,7 @@ class Server extends Test\Unit\Suite
->isInstanceOf(Websocket\Connection::class);
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -77,7 +78,7 @@ class Server extends Test\Unit\Suite
->isIdenticalTo($request);
}
- public function case_constructor_with_an_undefined_request()
+ public function case_constructor_with_an_undefined_request(): void
{
$this
->given($socket = new Socket\Server('tcp://*:1234'))
@@ -89,7 +90,7 @@ class Server extends Test\Unit\Suite
->isInstanceOf(Http\Request::class);
}
- public function case_do_handshake_rfc6455()
+ public function case_do_handshake_rfc6455(): void
{
$self = $this;
@@ -142,7 +143,7 @@ class Server extends Test\Unit\Suite
]);
}
- public function case_do_handshake_hybi00()
+ public function case_do_handshake_hybi00(): void
{
$self = $this;
@@ -202,7 +203,7 @@ class Server extends Test\Unit\Suite
]);
}
- public function case_do_handshake_undefined_protocol()
+ public function case_do_handshake_undefined_protocol(): void
{
$this
->given(
@@ -221,13 +222,13 @@ class Server extends Test\Unit\Suite
},
$this->calling($socket)->getCurrentNode = $node
)
- ->exception(function () use ($server) {
+ ->exception(function () use ($server): void {
$this->invoke($server)->doHandshake();
})
->isInstanceOf(Websocket\Exception\BadProtocol::class);
}
- public function case_set_request()
+ public function case_set_request(): void
{
$this
->given(
@@ -242,7 +243,7 @@ class Server extends Test\Unit\Suite
->isIdenticalTo($requestA);
}
- public function case_get_request()
+ public function case_get_request(): void
{
$this
->given(
diff --git a/Test/Unit/Socket.php b/Test/Unit/Socket.php
index 53eb452..d96164d 100644
--- a/Test/Unit/Socket.php
+++ b/Test/Unit/Socket.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -45,12 +47,11 @@ use Hoa\Websocket\Socket as SUT;
*
* Test suite for the socket class.
*
- * @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Socket extends Test\Unit\Suite
{
- public function case_is_a_socket()
+ public function case_is_a_socket(): void
{
$this
->when($result = new SUT('tcp://hoa-project:net:8889'))
@@ -59,7 +60,7 @@ class Socket extends Test\Unit\Suite
->isInstanceOf('Hoa\Socket\Socket');
}
- public function case_constructor()
+ public function case_constructor(): void
{
$this
->given(
@@ -83,7 +84,7 @@ class Socket extends Test\Unit\Suite
->isEqualTo($endPoint);
}
- public function case_get_endpoint()
+ public function case_get_endpoint(): void
{
$this
->given(
@@ -98,12 +99,12 @@ class Socket extends Test\Unit\Suite
->isEqualTo($endPoint);
}
- public function case_is_ws_transport_registered()
+ public function case_is_ws_transport_registered(): void
{
$this->_case_is_transport_registered('ws');
}
- public function case_is_wss_transport_registered()
+ public function case_is_wss_transport_registered(): void
{
$this->_case_is_transport_registered('wss');
}
@@ -118,16 +119,16 @@ class Socket extends Test\Unit\Suite
->isTrue();
}
- public function case_transport_factory_invalid_URI()
+ public function case_transport_factory_invalid_URI(): void
{
$this
- ->exception(function () {
+ ->exception(function (): void {
SUT::transportFactory('foo');
})
->isInstanceOf('Hoa\Websocket\Exception');
}
- public function case_transport_unsecured_domain_with_port_with_endpoint()
+ public function case_transport_unsecured_domain_with_port_with_endpoint(): void
{
$this->_case_transport_factory(
'ws://hoa-project.net:8889/foobar',
@@ -141,7 +142,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_unsecured_domain_with_port_without_endpoint()
+ public function case_transport_unsecured_domain_with_port_without_endpoint(): void
{
$this->_case_transport_factory(
'ws://hoa-project.net:8889',
@@ -155,7 +156,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_unsecured_domain_without_port_without_endpoint()
+ public function case_transport_unsecured_domain_without_port_without_endpoint(): void
{
$this->_case_transport_factory(
'ws://hoa-project.net',
@@ -169,7 +170,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_secured_domain_with_port_with_endpoint()
+ public function case_transport_secured_domain_with_port_with_endpoint(): void
{
$this->_case_transport_factory(
'wss://hoa-project.net:8889/foobar',
@@ -183,7 +184,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_secured_domain_with_port_without_endpoint()
+ public function case_transport_secured_domain_with_port_without_endpoint(): void
{
$this->_case_transport_factory(
'wss://hoa-project.net:8889',
@@ -197,7 +198,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_secured_domain_without_port_without_endpoint()
+ public function case_transport_secured_domain_without_port_without_endpoint(): void
{
$this->_case_transport_factory(
'wss://hoa-project.net',
@@ -211,7 +212,7 @@ class Socket extends Test\Unit\Suite
);
}
- public function case_transport_query_strings_in_the_endpoint()
+ public function case_transport_query_strings_in_the_endpoint(): void
{
$this->_case_transport_factory(
'wss://hoa-project.net:8889/hello/world?foo=bar&baz=qux',