2017-12-06 01:21:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Parallel\Test\Context;
|
|
|
|
|
|
|
|
use Amp\Parallel\Context\Process;
|
|
|
|
use Amp\PHPUnit\TestCase;
|
|
|
|
use Amp\Promise;
|
|
|
|
|
|
|
|
class ProcessTest extends TestCase {
|
|
|
|
public function testBasicProcess() {
|
|
|
|
$process = new Process([
|
2017-12-10 22:37:33 +01:00
|
|
|
__DIR__ . "/test-process.php",
|
|
|
|
"Test"
|
2017-12-06 01:21:39 +01:00
|
|
|
]);
|
|
|
|
$process->start();
|
|
|
|
$this->assertSame("Test", Promise\wait($process->join()));
|
|
|
|
}
|
2017-12-10 22:37:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
|
|
|
* @expectedExceptionMessage No string provided
|
|
|
|
*/
|
|
|
|
public function testFailingProcess() {
|
|
|
|
$process = new Process(__DIR__ . "/test-process.php");
|
|
|
|
$process->start();
|
|
|
|
Promise\wait($process->join());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
|
|
|
* @expectedExceptionMessage No script found at 'test-process.php'
|
|
|
|
*/
|
|
|
|
public function testInvalidScriptPath() {
|
|
|
|
$process = new Process("test-process.php");
|
|
|
|
$process->start();
|
|
|
|
Promise\wait($process->join());
|
|
|
|
}
|
2017-12-13 20:56:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
|
|
|
* @expectedExceptionMessage The given data cannot be sent because it is not serializable
|
|
|
|
*/
|
|
|
|
public function testInvalidResult() {
|
|
|
|
$process = new Process(__DIR__ . "/invalid-result-process.php");
|
|
|
|
$process->start();
|
|
|
|
var_dump(Promise\wait($process->join()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
|
|
|
* @expectedExceptionMessage Script did not return a callable function
|
|
|
|
*/
|
|
|
|
public function testNoCallbackReturned() {
|
|
|
|
$process = new Process(__DIR__ . "/no-callback-process.php");
|
|
|
|
$process->start();
|
|
|
|
var_dump(Promise\wait($process->join()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Parallel\Sync\PanicError
|
|
|
|
* @expectedExceptionMessage Uncaught ParseError in execution context
|
|
|
|
*/
|
|
|
|
public function testParseError() {
|
2017-12-13 21:21:37 +01:00
|
|
|
$process = new Process(__DIR__ . "/parse-error-process.inc");
|
2017-12-13 20:56:11 +01:00
|
|
|
$process->start();
|
|
|
|
var_dump(Promise\wait($process->join()));
|
|
|
|
}
|
2017-12-06 01:21:39 +01:00
|
|
|
}
|