From 5f5a901744544a6ef6544d1676f0c6970e3c86de Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 15 Oct 2018 10:12:17 -0500 Subject: [PATCH] Add Process::__debugInfo() Fixes #25. --- lib/Process.php | 12 ++++++++++++ test/ProcessTest.php | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/Process.php b/lib/Process.php index 8081b09..3cb1a35 100644 --- a/lib/Process.php +++ b/lib/Process.php @@ -269,4 +269,16 @@ class Process return $this->handle->stderr; } + + public function __debugInfo(): array + { + return [ + 'command' => $this->getCommand(), + 'cwd' => $this->getWorkingDirectory(), + 'env' => $this->getEnv(), + 'options' => $this->getOptions(), + 'pid' => $this->pid, + 'status' => $this->handle ? $this->handle->status : -1, + ]; + } } diff --git a/test/ProcessTest.php b/test/ProcessTest.php index 95a7f4a..58f06f0 100644 --- a/test/ProcessTest.php +++ b/test/ProcessTest.php @@ -5,6 +5,7 @@ namespace Amp\Process\Test; use Amp\ByteStream\Message; use Amp\Delayed; use Amp\Loop; +use Amp\Process\Internal\ProcessStatus; use Amp\Process\Process; use Amp\Process\ProcessInputStream; use Amp\Process\ProcessOutputStream; @@ -358,4 +359,26 @@ class ProcessTest extends TestCase $this->assertSame(0, yield $process->join()); }); } + + public function testDebugInfo() { + Loop::run(function () { + $process = new Process(["php", __DIR__ . "/bin/worker.php"], __DIR__); + + $this->assertSame([ + 'command' => "'php' '" . __DIR__ . "/bin/worker.php'", + 'cwd' => __DIR__, + 'env' => [], + 'options' => [], + 'pid' => null, + 'status' => -1, + ], $process->__debugInfo()); + + yield $process->start(); + + $debug = $process->__debugInfo(); + + $this->assertInternalType('int', $debug['pid']); + $this->assertSame(ProcessStatus::RUNNING, $debug['status']); + }); + } }