1
0
mirror of https://github.com/danog/process.git synced 2024-11-26 20:24:43 +01:00

Add Process::__debugInfo()

Fixes #25.
This commit is contained in:
Aaron Piotrowski 2018-10-15 10:12:17 -05:00
parent d2d8d79615
commit 5f5a901744
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 35 additions and 0 deletions

View File

@ -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,
];
}
}

View File

@ -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']);
});
}
}