Skip to content

Commit 86cfede

Browse files
committed
Improve PHP 8.4+ support by avoiding implicitly nullable types
1 parent 9f54bcd commit 86cfede

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"php": ">=5.4",
1515
"ext-sqlite3": "*",
1616
"clue/ndjson-react": "^1.0",
17-
"react/child-process": "^0.6",
17+
"react/child-process": "^0.6.6",
1818
"react/event-loop": "^1.2",
19-
"react/promise": "^3 || ^2.7 || ^1.2.1"
19+
"react/promise": "^3.2 || ^2.7 || ^1.2.1"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"

src/Factory.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ class Factory
6262
* @param ?LoopInterface $loop
6363
* @param ?string $binary
6464
*/
65-
public function __construct(LoopInterface $loop = null, $binary = null)
65+
public function __construct($loop = null, $binary = null)
6666
{
67+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
68+
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
69+
}
70+
6771
$this->loop = $loop ?: Loop::get();
6872
$this->bin = $binary === null ? $this->php() : $binary;
6973

tests/FactoryTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ public function testConstructWitLoopAndBinaryAssignsBothVariables()
3232
$this->assertSame('php6.0', $ref->getValue($factory));
3333
}
3434

35+
public function testCtorThrowsForInvalidLoop()
36+
{
37+
if (method_exists($this, 'expectException')) {
38+
// PHPUnit 5.2+
39+
$this->expectException('InvalidArgumentException');
40+
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
41+
} else {
42+
// legacy PHPUnit
43+
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
44+
}
45+
46+
new Factory('loop');
47+
}
48+
3549
public function testLoadLazyReturnsDatabaseImmediately()
3650
{
3751
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();

tests/Io/BlockingDatabaseTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class BlockingDatabaseTest extends TestCase
99
public function testCtorThrowsForInvalidPath()
1010
{
1111
if (method_exists($this, 'expectException')) {
12+
// PHPUnit 5.2+
1213
$this->expectException('Exception');
1314
} else {
15+
// legacy PHPUnit
1416
$this->setExpectedException('Exception');
1517
}
1618
new BlockingDatabase('/dev/foobar');

0 commit comments

Comments
 (0)