1
0
mirror of https://github.com/danog/process.git synced 2024-12-04 10:38:04 +01:00
process/test/ProcessTest.php

86 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace Amp\Test\Process;
use Amp\Loop;
use Amp\Process\Process;
class ProcessTest extends \PHPUnit_Framework_TestCase {
const CMD_PROCESS = 'echo foo';
/**
* @expectedException \Amp\Process\StatusError
*/
public function testMultipleExecution() {
Loop::run(function() {
$process = new Process(self::CMD_PROCESS);
$process->start();
$process->start();
});
}
2017-01-16 05:49:41 +01:00
public function testIsRunning() {
Loop::run(function() {
2017-01-16 05:49:41 +01:00
$process = new Process("exit 42");
$process->start();
$promise = $process->join();
2017-01-16 05:49:41 +01:00
$this->assertTrue($process->isRunning());
yield $promise;
$this->assertFalse($process->isRunning());
});
2017-01-16 05:49:41 +01:00
}
public function testExecuteResolvesToExitCode() {
Loop::run(function() {
$process = new Process("exit 42");
$process->start();
$code = yield $process->join();
$this->assertSame(42, $code);
2017-01-16 05:49:41 +01:00
$this->assertFalse($process->isRunning());
});
}
public function testCommandCanRun() {
Loop::run(function() {
$process = new Process(self::CMD_PROCESS);
$process->start();
$promise = $process->join();
$completed = false;
2017-03-21 23:37:12 +01:00
$promise->onResolve(function() use (&$completed) { $completed = true; });
$this->assertFalse($completed);
$this->assertInternalType('int', $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();
$code = 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());
}
}