1
0
mirror of https://github.com/danog/process.git synced 2024-12-13 09:37:29 +01:00
process/test/ProcessTest.php

88 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Amp\Test\Process;
use Amp\Loop;
use Amp\Process\Process;
2017-06-16 05:53:33 +02:00
use PHPUnit\Framework\TestCase;
2017-06-16 05:53:33 +02:00
class ProcessTest extends TestCase {
const CMD_PROCESS = 'echo foo';
/**
* @expectedException \Amp\Process\StatusError
*/
public function testMultipleExecution() {
2017-06-15 19:11:38 +02:00
Loop::run(function () {
$process = new Process(self::CMD_PROCESS);
$process->start();
$process->start();
});
}
2017-01-16 05:49:41 +01:00
public function testIsRunning() {
2017-06-15 19:11:38 +02:00
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() {
2017-06-15 19:11:38 +02:00
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() {
2017-06-15 19:11:38 +02:00
Loop::run(function () {
$process = new Process(self::CMD_PROCESS);
$process->start();
$promise = $process->join();
$completed = false;
2017-06-15 19:11:38 +02:00
$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() {
2017-06-15 19:11:38 +02:00
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());
}
2017-06-15 19:11:38 +02:00
}