From d44ce589fe49858e69de639000e8173a4210b9e9 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 24 Oct 2024 13:14:08 -0400 Subject: [PATCH 1/3] Proposed 0.8 branch Drops support for PHP 7.0 and lower (only .7% current usage) --- composer.json | 4 +-- src/Process.php | 58 ++++++++++++----------------------- tests/AbstractProcessTest.php | 20 ------------ 3 files changed, 21 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index fba70b8..5312556 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/Process.php b/src/Process.php index 406e417..e8360c0 100644 --- a/src/Process.php +++ b/src/Process.php @@ -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'); @@ -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'); @@ -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; @@ -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; @@ -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; } @@ -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(); @@ -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; } @@ -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; @@ -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(); @@ -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(); @@ -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(); @@ -425,10 +407,8 @@ private function getCachedStatus() /** * Return the updated process status. - * - * @return array */ - private function getFreshStatus() + private function getFreshStatus() : array { $this->updateStatus(); @@ -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; diff --git a/tests/AbstractProcessTest.php b/tests/AbstractProcessTest.php index 4a81d0b..606336f 100644 --- a/tests/AbstractProcessTest.php +++ b/tests/AbstractProcessTest.php @@ -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()); @@ -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')) { From 06f4c8a3e13666b32ad0c32a1daefefab3bd09c9 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 24 Oct 2024 13:43:02 -0400 Subject: [PATCH 2/3] Remove PHP 5.3 - 7.0 unit tests --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 867104f..81c18b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From d40da4eeb3ae4fc4a589ab574b99110a3d016466 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 24 Oct 2024 13:49:04 -0400 Subject: [PATCH 3/3] Remove support for unit testing of HHVM, as it is no longer supported --- .github/workflows/ci.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81c18b1..3bbc466 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,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