Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add PHP >= 8 support + updated tests and workflow. #1014

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
6bc3958
Create test
josh-gaby May 12, 2023
b7aa6a5
Add missing properties to IoConnection.php
josh-gaby May 12, 2023
78c0e0e
Update to work with PHP 8.2
josh-gaby May 13, 2023
8e6acea
Update tests to run on version upto 8.2
josh-gaby May 13, 2023
84b3fe5
Merge pull request #1 from josh-gaby/php82
josh-gaby May 13, 2023
5c39aec
Allow manual workflow run
josh-gaby May 13, 2023
5961041
Merge pull request #2 from josh-gaby/php82
josh-gaby May 13, 2023
1022815
Update comments
josh-gaby May 13, 2023
62da503
Update tests
josh-gaby May 13, 2023
b45aa35
Merge pull request #3 from josh-gaby/php82
josh-gaby May 13, 2023
addf94f
Update PHPUnit to v9
josh-gaby May 13, 2023
67f655b
Update PHPUnit to v9
josh-gaby May 13, 2023
6b88bc1
Update workflow
josh-gaby May 13, 2023
6a6b3f9
Update workflow
josh-gaby May 13, 2023
95e07c0
Update workflow
josh-gaby May 13, 2023
cb3f72b
Update workflow
josh-gaby May 13, 2023
bd33ac5
Update workflow
josh-gaby May 13, 2023
b58f1fa
Update workflow
josh-gaby May 13, 2023
3020d28
Update workflow
josh-gaby May 13, 2023
d14857d
Update workflow
josh-gaby May 13, 2023
56b8cec
Update workflow
josh-gaby May 13, 2023
cd914b4
Update workflow
josh-gaby May 13, 2023
129c47e
Update workflow
josh-gaby May 13, 2023
4110b83
Update workflow
josh-gaby May 13, 2023
158e944
Update workflow
josh-gaby May 13, 2023
6bddff9
Update workflow
josh-gaby May 13, 2023
2112cd0
Update workflow
josh-gaby May 13, 2023
572f3d0
Update workflow
josh-gaby May 13, 2023
be721b4
Update workflow
josh-gaby May 13, 2023
a7ffaa1
Update workflow
josh-gaby May 13, 2023
e9d5aee
Update workflow
josh-gaby May 13, 2023
cf012e1
Update workflow
josh-gaby May 13, 2023
353284d
Update workflow
josh-gaby May 13, 2023
6bfc3fb
Update workflow
josh-gaby May 13, 2023
e2ab1f2
Update workflow
josh-gaby May 13, 2023
ee9e32f
Update workflow
josh-gaby May 13, 2023
3eb5ebd
Update test to use @before/@after annotations instead of setUp/tearDown
josh-gaby May 14, 2023
1b8afc5
Remove invalid configurations and add missing @covers
josh-gaby May 14, 2023
203b09f
Remove unused syntaxCheck from PHPUnit config
josh-gaby May 14, 2023
f03ed0d
Remove usage of symfony/http-foundation >= 6
josh-gaby May 14, 2023
6fa228f
Test switching to createMock
josh-gaby May 14, 2023
672cac4
Test switching to expectedException
josh-gaby May 14, 2023
b7de821
Test switching to createMock
josh-gaby May 14, 2023
5bbdaa3
Revert to getMock
josh-gaby May 14, 2023
51f73d3
Revert to getMock
josh-gaby May 14, 2023
3953527
Update checkout version
josh-gaby May 14, 2023
eba9487
Test extended testcase to allow switching between getMock/createMock
josh-gaby May 14, 2023
f662dfd
Test extended testcase to allow switching between getMock/createMock
josh-gaby May 14, 2023
f75aa4b
Test extended testcase to allow switching between getMock/createMock
josh-gaby May 14, 2023
2ae3ea8
Test extended testcase to allow switching between getMock/createMock
josh-gaby May 14, 2023
3c0701e
Test extended testcase to allow switching between getMock/createMock
josh-gaby May 14, 2023
2578564
Add switches to support PHPUnit < 6 and > 6
josh-gaby May 14, 2023
b70073f
Add switches to support PHPUnit < 6 and > 6
josh-gaby May 14, 2023
12a1a13
Add switches to support PHPUnit < 6 and > 6
josh-gaby May 14, 2023
3e7f7f1
Update to getMockBuilder
josh-gaby May 14, 2023
2904585
Revert some getMockBuilder
josh-gaby May 14, 2023
c62998b
Update TopicTest
josh-gaby May 14, 2023
f3559e9
Update TopicTest
josh-gaby May 14, 2023
cd493aa
Update Connection
josh-gaby May 14, 2023
8f4a6dd
Revert changes
josh-gaby May 14, 2023
6590803
Revert changes
josh-gaby May 14, 2023
836a02c
Update asserts
josh-gaby May 14, 2023
ccfaf84
Try list() for array destructuring in testConnIsRemovedFromTopicOnClose
josh-gaby May 14, 2023
533b273
list() for array destructuring
josh-gaby May 14, 2023
3e8e3c2
Merge pull request #4 from josh-gaby/php82
josh-gaby May 14, 2023
755977d
Remove workflow_dispatch
josh-gaby May 14, 2023
003d972
Merge pull request #5 from josh-gaby/php82
josh-gaby May 14, 2023
634792a
Remove unnecessary include from HttpServer
josh-gaby May 14, 2023
d13402f
Merge pull request #6 from josh-gaby/php82
josh-gaby May 14, 2023
136f614
Add http-foundation 6.0 back
josh-gaby May 14, 2023
7c28424
Test return types
josh-gaby May 14, 2023
54c0aef
Allow manual work flow runs
josh-gaby May 14, 2023
e7e7e32
Horrible hack to allow symfony/http-foundation >= 6.0 (definitely nee…
josh-gaby May 14, 2023
dc69b28
Update to horrible hack to allow symfony/http-foundation >= 6.0 while…
josh-gaby May 14, 2023
6d2f6a2
Merge pull request #7 from josh-gaby/php82
josh-gaby May 14, 2023
bc519b9
Allow the WsConnection close function to include the optional reason.
josh-gaby May 23, 2023
56a7c2b
Update ci.yml
josh-gaby Jul 16, 2023
4311014
Update ci.yml
josh-gaby Jul 16, 2023
be5e072
Add missing __isset function to the IoConnection class.
josh-gaby Jan 9, 2024
688b810
refactor: switch to using a dynamic properties trait
josh-gaby Aug 9, 2024
dc5edca
refactor: switch IoConnection to use the new dynamic properties trait
josh-gaby Aug 9, 2024
30959f5
ci: re-enable running ci on a schedule
josh-gaby Aug 9, 2024
0505b4a
Merge branch 'master' into php82
josh-gaby Aug 9, 2024
4982587
Merge pull request #8 from josh-gaby/php82
josh-gaby Aug 9, 2024
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
60 changes: 41 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,61 @@ jobs:
runs-on: "ubuntu-20.04"

strategy:
fail-fast: false
matrix:
php-version:
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
dependencies:
- "highest"
include:
- dependencies: "lowest"
php-version: "5.4"
- php: 5.4
phpunit: phpunit/phpunit ^4
can-fail: false
- php: 5.5
phpunit: phpunit/phpunit ^4
can-fail: false
- php: 5.6
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 7.0
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 7.1
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 7.2
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 7.3
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 7.4
phpunit: phpunit/phpunit ^5
can-fail: false
- php: 8.0
phpunit: phpunit/phpunit ^9
can-fail: false
- php: 8.1
phpunit: phpunit/phpunit ^9
can-fail: false
- php: 8.2
phpunit: phpunit/phpunit ^9
can-fail: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
php-version: "${{ matrix.php }}"
coverage: "none"
ini-values: "zend.assertions=1"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"
- name: "Update PHPUnit version"
run: composer require --dev --with-all-dependencies --no-install ${{ matrix.phpunit }}

- name: "Install dependencies"
run: composer update

- name: "Run PHPUnit"
run: "vendor/bin/phpunit"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ phpunit.xml
reports
sandbox
vendor
composer.lock
composer.lock
.idea/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
, "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0"
}
, "require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "^9"
}
}
16 changes: 1 addition & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
forceCoversAnnotation="true"
mapTestClassNameToCoveredClassName="true"
bootstrap="tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false"
stopOnError="false"
>

Expand All @@ -15,16 +13,4 @@
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="integration">
<directory>./tests/integration/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
3 changes: 3 additions & 0 deletions src/Ratchet/Http/HttpRequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
use Ratchet\MessageInterface;
use Ratchet\ConnectionInterface;
use GuzzleHttp\Psr7\Message;
use Ratchet\Traits\DynamicPropertiesTrait;

/**
* This class receives streaming data from a client request
* and parses HTTP headers, returning a PSR-7 Request object
* once it's been buffered
*/
class HttpRequestParser implements MessageInterface {
use DynamicPropertiesTrait;

const EOM = "\r\n\r\n";

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Ratchet/Http/HttpServer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Ratchet\Http;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;
use Ratchet\Traits\DynamicPropertiesTrait;

class HttpServer implements MessageComponentInterface {
use CloseResponseTrait;
use CloseResponseTrait, DynamicPropertiesTrait;

/**
* Buffers incoming HTTP requests returning a Guzzle Request when coalesced
Expand All @@ -26,6 +27,7 @@ public function __construct(HttpServerInterface $component) {
$this->_reqParser = new HttpRequestParser;
}


/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Ratchet/Http/OriginCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ function onClose(ConnectionInterface $conn) {
function onError(ConnectionInterface $conn, \Exception $e) {
return $this->_component->onError($conn, $e);
}
}
}
6 changes: 3 additions & 3 deletions src/Ratchet/Http/Router.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Ratchet\Http;
use Ratchet\ConnectionInterface;
use GuzzleHttp\Psr7\Query;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Ratchet\ConnectionInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use GuzzleHttp\Psr7\Query;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;

class Router implements HttpServerInterface {
use CloseResponseTrait;
Expand Down
3 changes: 2 additions & 1 deletion src/Ratchet/Server/IoConnection.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
namespace Ratchet\Server;
use Ratchet\ConnectionInterface;
use Ratchet\Traits\DynamicPropertiesTrait;
use React\Socket\ConnectionInterface as ReactConn;

/**
* {@inheritdoc}
*/
class IoConnection implements ConnectionInterface {
use DynamicPropertiesTrait;
/**
* @var \React\Socket\ConnectionInterface
*/
protected $conn;


/**
* @param \React\Socket\ConnectionInterface $conn
*/
Expand Down
47 changes: 25 additions & 22 deletions src/Ratchet/Server/IoServer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Ratchet\Server;
use Ratchet\MessageComponentInterface;
use Ratchet\Traits\DynamicPropertiesTrait;
use React\EventLoop\LoopInterface;
use React\Socket\ServerInterface;
use React\EventLoop\Factory as LoopFactory;
Expand All @@ -12,6 +13,8 @@
* Events are delegated through this to attached applications
*/
class IoServer {
use DynamicPropertiesTrait;

/**
* @var \React\EventLoop\LoopInterface
*/
Expand Down Expand Up @@ -80,61 +83,61 @@ public function run() {
* @param \React\Socket\ConnectionInterface $conn
*/
public function handleConnect($conn) {
$conn->decor = new IoConnection($conn);
$conn->decor->resourceId = (int)$conn->stream;
$io_conn = new IoConnection($conn);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing $conn->decor should still be left to avoid a breaking change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decor is not a property of \React\Socket\ConnectionInterface so can't be left in because php 8 deprecated dynamic property creation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe we also make a PR to reactphp/socket to add #[AllowDynamicProperties] to the interface https://github.com/reactphp/socket/blob/3.x/src/ConnectorInterface.php

Copy link

@Tofandel Tofandel Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we simply use spl storage locally in IoServer to store the decor and retrieve it when needed

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

$uri = $conn->getRemoteAddress();
$conn->decor->remoteAddress = trim(
$io_conn->remoteAddress = trim(
parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST),
'[]'
);

$this->app->onOpen($conn->decor);
$this->app->onOpen($io_conn);

$conn->on('data', function ($data) use ($conn) {
$this->handleData($data, $conn);
$conn->on('data', function ($data) use ($io_conn) {
$this->handleData($data, $io_conn);
});
$conn->on('close', function () use ($conn) {
$this->handleEnd($conn);
$conn->on('close', function () use ($io_conn) {
$this->handleEnd($io_conn);
});
$conn->on('error', function (\Exception $e) use ($conn) {
$this->handleError($e, $conn);
$conn->on('error', function (\Exception $e) use ($io_conn) {
$this->handleError($e, $io_conn);
});
}

/**
* Data has been received from React
* @param string $data
* @param \React\Socket\ConnectionInterface $conn
* @param \Ratchet\ConnectionInterface $io_conn
*/
public function handleData($data, $conn) {
public function handleData($data, $io_conn) {
Copy link

@Tofandel Tofandel Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parameter there and in the other methods is a breaking change, because IoServer can be extended

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this a breaking change, however it was done because \React\Socket\ConnectionInterface doesn't actually have the decor property previously being used to pass the connection around and PHP 8 deprecated dymanic property creation.

try {
$this->app->onMessage($conn->decor, $data);
$this->app->onMessage($io_conn, $data);
} catch (\Exception $e) {
$this->handleError($e, $conn);
$this->handleError($e, $io_conn);
}
}

/**
* A connection has been closed by React
* @param \React\Socket\ConnectionInterface $conn
* @param \Ratchet\ConnectionInterface $io_conn
*/
public function handleEnd($conn) {
public function handleEnd($io_conn) {
try {
$this->app->onClose($conn->decor);
$this->app->onClose($io_conn);
} catch (\Exception $e) {
$this->handleError($e, $conn);
$this->handleError($e, $io_conn);
}

unset($conn->decor);
unset($io_conn);
}

/**
* An error has occurred, let the listening application know
* @param \Exception $e
* @param \React\Socket\ConnectionInterface $conn
* @param \Ratchet\ConnectionInterface $io_conn
*/
public function handleError(\Exception $e, $conn) {
$this->app->onError($conn->decor, $e);
public function handleError(\Exception $e, $io_conn) {
$this->app->onError($io_conn, $e);
}
}
2 changes: 1 addition & 1 deletion src/Ratchet/Session/SessionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This component will allow access to session data from your website for each user connected
* Symfony HttpFoundation is required for this component to work
* Your website must also use Symfony HttpFoundation Sessions to read your sites session data
* If your are not using at least PHP 5.4 you must include a SessionHandlerInterface stub (is included in Symfony HttpFoundation, loaded w/ composer)
* If you're not using at least PHP 5.4 you must include a SessionHandlerInterface stub (is included in Symfony HttpFoundation, loaded w/ composer)
*/
class SessionProvider implements HttpServerInterface {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Ratchet\Session\Storage\Proxy;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;

class VirtualProxy extends SessionHandlerProxy {
/**
* @var string
*/
protected $_sessionId;

/**
* @var string
*/
protected $_sessionName;

/**
* {@inheritdoc}
*/
public function __construct(\SessionHandlerInterface $handler) {
parent::__construct($handler);

$this->saveHandlerName = 'user';
$this->_sessionName = ini_get('session.name');
}

/**
* {@inheritdoc}
*/
public function getId(): string {
return $this->_sessionId;
}

/**
* {@inheritdoc}
*/
public function setId($id) {
$this->_sessionId = $id;
}

/**
* {@inheritdoc}
*/
public function getName(): string {
return $this->_sessionName;
}

/**
* DO NOT CALL THIS METHOD
* @internal
*/
public function setName($name) {
throw new \RuntimeException("Can not change session name in VirtualProxy");
}
}
Loading