Skip to content

Commit bf021f7

Browse files
authored
Merge pull request #114 from clue-labs/nullable-backport
[0.6.x] Improve PHP 8.4+ support by avoiding implicitly nullable types
2 parents 7ee5a33 + 17683ef commit bf021f7

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- ubuntu-24.04
1515
- windows-2022
1616
php:
17+
- 8.4
1718
- 8.3
1819
- 8.2
1920
- 8.1

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
"php": ">=5.3.0",
3030
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
3131
"react/event-loop": "^1.2",
32-
"react/stream": "^1.2"
32+
"react/stream": "^1.4"
3333
},
3434
"require-dev": {
3535
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
36-
"react/socket": "^1.8",
36+
"react/socket": "^1.16",
3737
"sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0"
3838
},
3939
"autoload": {

src/Process.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ class Process extends EventEmitter
112112
* @param null|array $fds File descriptors to allocate for this process (or null = default STDIO streams)
113113
* @throws \LogicException On windows or when proc_open() is not installed
114114
*/
115-
public function __construct($cmd, $cwd = null, array $env = null, array $fds = null)
115+
public function __construct($cmd, $cwd = null, $env = null, $fds = null)
116116
{
117+
if ($env !== null && !\is_array($env)) { // manual type check to support legacy PHP < 7.1
118+
throw new \InvalidArgumentException('Argument #3 ($env) expected null|array');
119+
}
120+
if ($fds !== null && !\is_array($fds)) { // manual type check to support legacy PHP < 7.1
121+
throw new \InvalidArgumentException('Argument #4 ($fds) expected null|array');
122+
}
117123
if (!\function_exists('proc_open')) {
118124
throw new \LogicException('The Process class relies on proc_open(), which is not available on your PHP installation.');
119125
}
@@ -164,8 +170,11 @@ public function __construct($cmd, $cwd = null, array $env = null, array $fds = n
164170
* @param float $interval Interval to periodically monitor process state (seconds)
165171
* @throws \RuntimeException If the process is already running or fails to start
166172
*/
167-
public function start(LoopInterface $loop = null, $interval = 0.1)
173+
public function start($loop = null, $interval = 0.1)
168174
{
175+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
176+
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
177+
}
169178
if ($this->isRunning()) {
170179
throw new \RuntimeException('Process is already running');
171180
}

tests/AbstractProcessTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ abstract class AbstractProcessTest extends TestCase
1111
{
1212
abstract public function createLoop();
1313

14+
public function testCtorThrowsForInvalidEnv()
15+
{
16+
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($env) expected null|array');
17+
new Process('exit 0', null, 'env');
18+
}
19+
20+
public function testCtorThrowsForInvalidFds()
21+
{
22+
$this->setExpectedException('InvalidArgumentException', 'Argument #4 ($fds) expected null|array');
23+
new Process('exit 0', null, null, 'fds');
24+
}
25+
1426
public function testGetCommand()
1527
{
1628
$process = new Process('echo foo', null, null, array());
@@ -126,6 +138,14 @@ public function testStartWithCustomPipesWillAssignPipes()
126138
$this->assertInstanceOf('React\Stream\WritableStreamInterface', $process->pipes[3]);
127139
}
128140

141+
public function testStartWithInvalidLoopWillThrow()
142+
{
143+
$process = new Process('exit 0', null, null, array());
144+
145+
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
146+
$process->start('loop');
147+
}
148+
129149
public function testStartWithInvalidFileDescriptorPathWillThrowWithoutCallingCustomErrorHandler()
130150
{
131151
if (defined('HHVM_VERSION')) {

0 commit comments

Comments
 (0)