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

Proposed 0.8 branch #109

Open
wants to merge 3 commits into
base: 0.7.x
Choose a base branch
from
Open
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
25 changes: 0 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand All @@ -42,23 +37,3 @@ jobs:
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}
- run: php examples/13-benchmark-throughput.php

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar install
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm composer.phar install
- name: Run hhvm vendor/bin/phpunit
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm vendor/bin/phpunit
- name: Run hhvm examples/13-benchmark-throughput.php
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm examples/13-benchmark-throughput.php
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
}
],
"require": {
"php": ">=5.3.0",
"php": ">=7.1",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.2",
"react/stream": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"phpunit/phpunit": "^9.6 || ^7.0",
"react/socket": "^1.16",
"sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0"
},
Expand Down
58 changes: 19 additions & 39 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class Process extends EventEmitter
* Constructor.
*
* @param string $cmd Command line to run
* @param null|string $cwd Current working directory or null to inherit
* @param null|array $env Environment variables or null to inherit
* @param null|array $fds File descriptors to allocate for this process (or null = default STDIO streams)
* @param ?string $cwd Current working directory or null to inherit
* @param ?array $env Environment variables or null to inherit
* @param ?array $fds File descriptors to allocate for this process (or null = default STDIO streams)
* @throws \LogicException On windows or when proc_open() is not installed
*/
public function __construct($cmd, $cwd = null, $env = null, $fds = null)
public function __construct(string $cmd, ?string $cwd = null, ?array $env = null, ?array $fds = null)
{
if ($env !== null && !\is_array($env)) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #3 ($env) expected null|array');
Expand Down Expand Up @@ -160,7 +160,7 @@ public function __construct($cmd, $cwd = null, $env = null, $fds = null)
* @param float $interval Interval to periodically monitor process state (seconds)
* @throws \RuntimeException If the process is already running or fails to start
*/
public function start($loop = null, $interval = 0.1)
public function start(?LoopInterface $loop = null, float $interval = 0.1) : void
{
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
Expand Down Expand Up @@ -259,7 +259,7 @@ public function start($loop = null, $interval = 0.1)
* This method should only be invoked via the periodic timer that monitors
* the process state.
*/
public function close()
public function close() : void
{
if ($this->process === null) {
return;
Expand Down Expand Up @@ -289,10 +289,10 @@ public function close()
/**
* Terminate the process with an optional signal.
*
* @param int $signal Optional signal (default: SIGTERM)
* @param ?int $signal Optional signal (default: SIGTERM)
* @return bool Whether the signal was sent successfully
*/
public function terminate($signal = null)
public function terminate(?int $signal = null) : bool
{
if ($this->process === null) {
return false;
Expand All @@ -307,10 +307,8 @@ public function terminate($signal = null)

/**
* Get the command string used to launch the process.
*
* @return string
*/
public function getCommand()
public function getCommand() : string
{
return $this->cmd;
}
Expand All @@ -323,20 +321,16 @@ public function getCommand()
*
* Null may also be returned if the process has terminated, but the exit
* code could not be determined.
*
* @return int|null
*/
public function getExitCode()
public function getExitCode() : ?int
{
return $this->exitCode;
}

/**
* Get the process ID.
*
* @return int|null
*/
public function getPid()
public function getPid() : ?int
{
$status = $this->getCachedStatus();

Expand All @@ -348,10 +342,8 @@ public function getPid()
*
* This value is only meaningful if isStopped() has returned true. Null will
* be returned if the process was never stopped.
*
* @return int|null
*/
public function getStopSignal()
public function getStopSignal() : ?int
{
return $this->stopSignal;
}
Expand All @@ -361,20 +353,16 @@ public function getStopSignal()
*
* This value is only meaningful if isTerminated() has returned true. Null
* will be returned if the process was never terminated.
*
* @return int|null
*/
public function getTermSignal()
public function getTermSignal() : ?int
{
return $this->termSignal;
}

/**
* Return whether the process is still running.
*
* @return bool
*/
public function isRunning()
public function isRunning() : bool
{
if ($this->process === null) {
return false;
Expand All @@ -387,10 +375,8 @@ public function isRunning()

/**
* Return whether the process has been stopped by a signal.
*
* @return bool
*/
public function isStopped()
public function isStopped() : bool
{
$status = $this->getFreshStatus();

Expand All @@ -399,10 +385,8 @@ public function isStopped()

/**
* Return whether the process has been terminated by an uncaught signal.
*
* @return bool
*/
public function isTerminated()
public function isTerminated() : bool
{
$status = $this->getFreshStatus();

Expand All @@ -411,10 +395,8 @@ public function isTerminated()

/**
* Return the cached process status.
*
* @return array
*/
private function getCachedStatus()
private function getCachedStatus() : array
{
if ($this->status === null) {
$this->updateStatus();
Expand All @@ -425,10 +407,8 @@ private function getCachedStatus()

/**
* Return the updated process status.
*
* @return array
*/
private function getFreshStatus()
private function getFreshStatus() : array
{
$this->updateStatus();

Expand All @@ -442,7 +422,7 @@ private function getFreshStatus()
* signaled, respectively. Otherwise, signal values will remain as-is so the
* corresponding getter methods may be used at a later point in time.
*/
private function updateStatus()
private function updateStatus() : void
{
if ($this->process === null) {
return;
Expand Down
20 changes: 0 additions & 20 deletions tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ abstract class AbstractProcessTest extends TestCase
{
abstract public function createLoop();

public function testCtorThrowsForInvalidEnv()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($env) expected null|array');
new Process('exit 0', null, 'env');
}

public function testCtorThrowsForInvalidFds()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #4 ($fds) expected null|array');
new Process('exit 0', null, null, 'fds');
}

public function testGetCommand()
{
$process = new Process('echo foo', null, null, array());
Expand Down Expand Up @@ -138,14 +126,6 @@ public function testStartWithCustomPipesWillAssignPipes()
$this->assertInstanceOf('React\Stream\WritableStreamInterface', $process->pipes[3]);
}

public function testStartWithInvalidLoopWillThrow()
{
$process = new Process('exit 0', null, null, array());

$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
$process->start('loop');
}

public function testStartWithInvalidFileDescriptorPathWillThrowWithoutCallingCustomErrorHandler()
{
if (defined('HHVM_VERSION')) {
Expand Down