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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
dependencies:
- "highest"
include:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ composer require cboden/ratchet:^0.4.4
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.4 through PHP 8.1+ with limited support for PHP 8.2+.
extensions and supports running on legacy PHP 5.4 through PHP 8.2+ with limited support for newer PHP.
It's *highly recommended to use the latest supported PHP version* for this project.

See above note about [Reviving Ratchet](#reviving-ratchet) for newer PHP support.
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResult="false"
colors="true">
colors="true"
convertDeprecationsToExceptions="true">
<testsuites>
<testsuite name="Ratchet test suite">
<directory>./tests/unit/</directory>
Expand All @@ -16,4 +17,7 @@
<directory>./src/</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1" />
</php>
</phpunit>
3 changes: 3 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
</php>
</phpunit>
5 changes: 5 additions & 0 deletions src/Ratchet/AbstractConnectionDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
/**
* Wraps ConnectionInterface objects via the decorator pattern but allows
* parameters to bubble through with magic methods
*
* Note that this instance does not use the `#[\AllowDynamicProperties]`
* attribute for PHP 8.2+ compatibility as any properties added to this class
* will be forwarded to the wrapped instance.
*
* @todo It sure would be nice if I could make most of this a trait...
*/
abstract class AbstractConnectionDecorator implements ConnectionInterface {
Expand Down
6 changes: 6 additions & 0 deletions src/Ratchet/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
/**
* A proxy object representing a connection to the application
* This acts as a container to store data (in memory) about the connection
*
* Note that Ratchet makes heavy use of the decorator pattern and dynamic
* properties. This means any object that implements this interface may not
* have the same methods or properties as the ones in this interface.
* Implementations of this interface may have to use the `#[\AllowDynamicProperties]`
* attribute to allow dynamic properties on PHP 8.2+.
*/
interface ConnectionInterface {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/Ratchet/Server/IoConnection.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
namespace Ratchet\Server;
use Ratchet\ConnectionInterface;
use React\Socket\ConnectionInterface as ReactConn;
use React\Socket\ConnectionInterface as SocketConnection;

/**
* {@inheritdoc}
*/
#[\AllowDynamicProperties]
class IoConnection implements ConnectionInterface {
/**
* @var \React\Socket\ConnectionInterface
Expand All @@ -16,7 +17,7 @@ class IoConnection implements ConnectionInterface {
/**
* @param \React\Socket\ConnectionInterface $conn
*/
public function __construct(ReactConn $conn) {
public function __construct(SocketConnection $conn) {
$this->conn = $conn;
}

Expand Down
8 changes: 7 additions & 1 deletion src/Ratchet/Server/IoServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Ratchet\Server;
use Ratchet\MessageComponentInterface;
use React\EventLoop\LoopInterface;
use React\Socket\ConnectionInterface as SocketConnection;
use React\Socket\ServerInterface;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor;
Expand Down Expand Up @@ -79,8 +80,13 @@ public function run() {
* Triggered when a new connection is received from React
* @param \React\Socket\ConnectionInterface $conn
*/
public function handleConnect($conn) {
public function handleConnect(SocketConnection $conn) {
// assign dynamic `$decor` property used by Ratchet without raising notice on PHP 8.2+
// need this hack because we can't use `#[\AllowDynamicProperties]` on vendor code
set_error_handler(function () { }, E_DEPRECATED);
$conn->decor = new IoConnection($conn);
restore_error_handler();

$conn->decor->resourceId = (int)$conn->stream;

$uri = $conn->getRemoteAddress();
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUpConnection() {
$this->_app = $this->getMockBuilder($this->getComponentClassString())->getMock();
$decorator = $this->getDecoratorClassString();
$this->_serv = new $decorator($this->_app);
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->_conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();

$this->doOpen($this->_conn);
}
Expand All @@ -34,7 +34,7 @@ public function isExpectedConnection() {

public function testOpen() {
$this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection());
$this->doOpen($this->getMockBuilder('Ratchet\ConnectionInterface')->getMock());
$this->doOpen($this->getMockBuilder('Ratchet\Mock\Connection')->getMock());
}

public function testOnClose() {
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/Ratchet/Mock/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Ratchet\Mock;
use Ratchet\ConnectionInterface;

#[\AllowDynamicProperties]
class Connection implements ConnectionInterface {
public $last = array(
'send' => ''
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/AbstractConnectionDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AbstractConnectionDecoratorTest extends TestCase {
* @before
*/
public function setUpConnection() {
$this->mock = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->mock = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$this->l1 = new ConnectionDecorator($this->mock);
$this->l2 = new ConnectionDecorator($this->l1);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Http/HttpRequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testIsEom($expected, $message) {
}

public function testBufferOverflowResponse() {
$conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();

$this->parser->maxSize = 20;

Expand All @@ -51,7 +51,7 @@ public function testBufferOverflowResponse() {
}

public function testReturnTypeIsRequest() {
$conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n");

$this->assertInstanceOf('Psr\Http\Message\RequestInterface', $return);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Http/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RouterTest extends TestCase {
* @before
*/
public function setUpConnection() {
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->_conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$this->_uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock();
$this->_req = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();
$this->_req
Expand Down Expand Up @@ -80,7 +80,7 @@ public function testControllerOnOpen() {
$this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller)));
$this->_router->onOpen($this->_conn, $this->_req);

$expectedConn = $this->isInstanceOf('Ratchet\ConnectionInterface');
$expectedConn = $this->isInstanceOf('Ratchet\Mock\Connection');
$controller->expects($this->once())->method('onOpen')->with($expectedConn, $this->_req);

$this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller)));
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/Server/IoServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ public function testNoLoopProvidedError() {

public function testOnErrorPassesException() {
$conn = $this->getMockBuilder('React\\Socket\\ConnectionInterface')->getMock();

// assign dynamic property without raising notice on PHP 8.2+
set_error_handler(function () { }, E_DEPRECATED);
$conn->decor = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock();
restore_error_handler();

$err = new \Exception("Nope");

$this->app->expects($this->once())->method('onError')->with($conn->decor, $err);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Server/IpBlackListComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testUnblockingSilentlyFails() {
}

protected function newConn() {
$conn = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock();
$conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$conn->remoteAddress = '127.0.0.1';

return $conn;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Wamp/TopicManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TopicManagerTest extends TestCase {
* @before
*/
public function setUpManager() {
$this->conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$this->mock = $this->getMockBuilder('Ratchet\Wamp\WampServerInterface')->getMock();
$this->mngr = new TopicManager($this->mock);

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Wamp/TopicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function testBroadcast() {
$name = 'Batman';
$protocol = json_encode(array(8, $name, $msg));

$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();

$first->expects($this->once())
->method('send')
Expand All @@ -65,9 +65,9 @@ public function testBroadcastWithExclude() {
$name = 'Excluding';
$protocol = json_encode(array(8, $name, $msg));

$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();
$third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();

$first->expects($this->once())
->method('send')
Expand All @@ -92,9 +92,9 @@ public function testBroadcastWithEligible() {
$name = 'Eligible';
$protocol = json_encode(array(8, $name, $msg));

$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock();
$first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();
$second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();
$third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\Mock\Connection')->getMock()))->getMock();

$first->expects($this->once())
->method('send')
Expand Down Expand Up @@ -161,6 +161,6 @@ public function testDoesNotHaveAfterRemove() {
}

protected function newConn() {
return new WampConnection($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock());
return new WampConnection($this->getMockBuilder('Ratchet\Mock\Connection')->getMock());
}
}
4 changes: 2 additions & 2 deletions tests/unit/Wamp/WampConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WampConnectionTest extends TestCase {
* @before
*/
public function setUpConnection() {
$this->mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock();
$this->mock = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$this->conn = new WampConnection($this->mock);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function testGetUriWhenNoCurieGiven() {
}

public function testClose() {
$mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock();
$mock = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock();
$conn = new WampConnection($mock);

$mock->expects($this->once())->method('close');
Expand Down