mirror of
https://github.com/danog/process.git
synced 2024-12-03 10:07:46 +01:00
88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Amp\Process\Test;
|
|
|
|
use Amp\Loop;
|
|
use Amp\Process\Process;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProcessTest extends TestCase {
|
|
const CMD_PROCESS = \DIRECTORY_SEPARATOR === "\\" ? "cmd /c echo foo" : "echo foo";
|
|
|
|
/**
|
|
* @expectedException \Amp\Process\StatusError
|
|
*/
|
|
public function testMultipleExecution() {
|
|
Loop::run(function () {
|
|
$process = new Process(self::CMD_PROCESS);
|
|
$process->start();
|
|
$process->start();
|
|
});
|
|
}
|
|
|
|
public function testIsRunning() {
|
|
Loop::run(function () {
|
|
$process = new Process(\DIRECTORY_SEPARATOR === "\\" ? "cmd /c exit 42" : "exit 42");
|
|
$process->start();
|
|
$promise = $process->join();
|
|
|
|
$this->assertTrue($process->isRunning());
|
|
|
|
yield $promise;
|
|
|
|
$this->assertFalse($process->isRunning());
|
|
});
|
|
}
|
|
|
|
public function testExecuteResolvesToExitCode() {
|
|
Loop::run(function () {
|
|
$process = new Process(\DIRECTORY_SEPARATOR === "\\" ? "cmd /c exit 42" : "exit 42");
|
|
$process->start();
|
|
|
|
$code = yield $process->join();
|
|
|
|
$this->assertSame(42, $code);
|
|
$this->assertFalse($process->isRunning());
|
|
});
|
|
}
|
|
|
|
public function testCommandCanRun() {
|
|
Loop::run(function () {
|
|
$process = new Process(self::CMD_PROCESS);
|
|
$process->start();
|
|
$promise = $process->join();
|
|
|
|
$completed = false;
|
|
$promise->onResolve(function () use (&$completed) { $completed = true; });
|
|
$this->assertFalse($completed);
|
|
$this->assertInternalType('int', yield $process->getPid());
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Amp\Process\ProcessException
|
|
* @expectedExceptionMessage The process was killed
|
|
*/
|
|
public function testKillSignals() {
|
|
Loop::run(function () {
|
|
$process = new Process(self::CMD_PROCESS);
|
|
$process->start();
|
|
$promise = $process->join();
|
|
|
|
$process->kill();
|
|
|
|
yield $promise;
|
|
});
|
|
}
|
|
|
|
public function testCommand() {
|
|
$process = new Process(self::CMD_PROCESS);
|
|
$this->assertSame(self::CMD_PROCESS, $process->getCommand());
|
|
}
|
|
|
|
public function testOptions() {
|
|
$process = new Process(self::CMD_PROCESS);
|
|
$this->assertSame([], $process->getOptions());
|
|
}
|
|
}
|