Skip to content

Improve PHP 8.4+ support by avoiding implicitly nullable types #41

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

Merged
merged 1 commit into from
Dec 6, 2024
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 @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
php:
- 8.4
- 8.3
- 8.2
- 8.1
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"require": {
"php": ">=5.3",
"react/event-loop": "^1.2",
"react/promise": "^3 || ^2.1 || ^1.2.1",
"react/promise-timer": "^1.9",
"react/socket": "^1.12"
"react/promise": "^3.2 || ^2.1 || ^1.2.1",
"react/promise-timer": "^1.11",
"react/socket": "^1.16"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
Expand Down
6 changes: 5 additions & 1 deletion src/ConnectionManagerDelay.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class ConnectionManagerDelay implements ConnectorInterface
* @param float $delay
* @param ?LoopInterface $loop
*/
public function __construct(ConnectorInterface $connectionManager, $delay, LoopInterface $loop = null)
public function __construct(ConnectorInterface $connectionManager, $delay, $loop = null)
{
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
}

$this->connectionManager = $connectionManager;
$this->delay = $delay;
$this->loop = $loop ?: Loop::get();
Expand Down
6 changes: 5 additions & 1 deletion src/ConnectionManagerTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class ConnectionManagerTimeout implements ConnectorInterface
* @param float $timeout
* @param ?LoopInterface $loop
*/
public function __construct(ConnectorInterface $connectionManager, $timeout, LoopInterface $loop = null)
public function __construct(ConnectorInterface $connectionManager, $timeout, $loop = null)
{
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
}

$this->connectionManager = $connectionManager;
$this->timeout = $timeout;
$this->loop = $loop ?: Loop::get();
Expand Down
12 changes: 10 additions & 2 deletions tests/ConnectionManagerDelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$cm = new ConnectionManagerDelay($unused, 0);

$ref = new \ReflectionProperty($cm, 'loop');
$ref->setAccessible(true);
$loop = $ref->getValue($cm);

$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}

public function testContructorThrowsExceptionForInvalidLoop()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();

$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
new ConnectionManagerDelay($unused, 0, 'loop');
}

public function testDelayTenth()
{
$will = $this->createConnectionManagerMock(true);
Expand Down
8 changes: 8 additions & 0 deletions tests/ConnectionManagerTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}

public function testContructorThrowsExceptionForInvalidLoop()
{
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();

$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
new ConnectionManagerTimeout($unused, 0, 'loop');
}

public function testTimeoutOkay()
{
$will = $this->createConnectionManagerMock(true);
Expand Down