Merge branch '2.3' into 2.7

* 2.3:
  [PropertyAccess] Reorder elements array after PropertyPathBuilder::replace
  [Routing] Skip PhpGeneratorDumperTest::testDumpWithTooManyRoutes on HHVM
  [Process] More robustness and deterministic tests

Conflicts:
	src/Symfony/Component/Process/Process.php
	src/Symfony/Component/Process/Tests/ProcessTest.php
This commit is contained in:
Nicolas Grekas 2015-12-23 07:54:35 +01:00
commit 5dc2bb30ca
7 changed files with 165 additions and 175 deletions

View File

@ -46,6 +46,12 @@ class PhpProcess extends Process
$php .= ' '.ProcessUtils::escapeArgument($file);
$script = null;
}
if ('\\' !== DIRECTORY_SEPARATOR && null !== $php) {
// exec is mandatory to deal with sending a signal to the process
// see https://github.com/symfony/symfony/issues/5030 about prepending
// command with exec
$php = 'exec '.$php;
}
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
}

View File

@ -76,12 +76,12 @@ class Process
private static $sigchild;
private static $posixSignals = array(
1 => 1, // SIGHUP
2 => 2, // SIGINT
3 => 3, // SIGQUIT
6 => 6, // SIGABRT
14 => 14, // SIGALRM
15 => 15, // SIGTERM
1, // SIGHUP
2, // SIGINT
3, // SIGQUIT
6, // SIGABRT
14, // SIGALRM
15, // SIGTERM
);
/**
@ -285,11 +285,19 @@ class Process
if (!isset($this->options['bypass_shell'])) {
$this->options['bypass_shell'] = true;
}
}
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors[3] = array('pipe', 'w');
$ptsWorkaround = null;
$commandline = '';
foreach (self::$posixSignals as $s) {
$commandline .= "trap 'echo s$s >&3' $s;";
}
// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
$commandline .= '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo x$code >&3; exit $code';
if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// Workaround for the bug, when PTS functionality is enabled.
// @see : https://bugs.php.net/69442
$ptsWorkaround = fopen(__FILE__, 'r');
@ -297,15 +305,15 @@ class Process
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
if ($ptsWorkaround) {
fclose($ptsWorkaround);
}
if (!is_resource($this->process)) {
throw new RuntimeException('Unable to launch a new process.');
}
$this->status = self::STATUS_STARTED;
if (isset($descriptors[3])) {
$this->fallbackStatus['pid'] = (int) fgets($this->processPipes->pipes[3]);
}
if ($this->tty) {
return;
}
@ -596,8 +604,6 @@ class Process
public function getExitCode()
{
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
}
@ -651,8 +657,6 @@ class Process
$this->requireProcessIsTerminated(__FUNCTION__);
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
@ -674,8 +678,6 @@ class Process
$this->requireProcessIsTerminated(__FUNCTION__);
if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
$this->stop(0);
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
@ -1245,22 +1247,8 @@ class Process
} else {
$this->processPipes = UnixPipes::create($this, $this->input);
}
$descriptors = $this->processPipes->getDescriptors($this->outputDisabled);
if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors[3] = array('pipe', 'w');
$trap = '';
foreach (self::$posixSignals as $s) {
$trap .= "trap 'echo s$s >&3' $s;";
}
$this->commandline = $trap.'{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$this->commandline .= 'pid=$!; echo p$pid >&3; wait $pid; code=$?; echo x$code >&3; exit $code';
}
return $descriptors;
return $this->processPipes->getDescriptors($this->outputDisabled);
}
/**
@ -1379,8 +1367,11 @@ class Process
$this->fallbackStatus['signaled'] = true;
$this->fallbackStatus['exitcode'] = -1;
$this->fallbackStatus['termsig'] = (int) substr($data, 1);
} elseif ('x' === $data[0] && !isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) substr($data, 1);
} elseif ('x' === $data[0]) {
$this->fallbackStatus['running'] = false;
if (!isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) substr($data, 1);
}
}
}
} else {
@ -1462,14 +1453,6 @@ class Process
return false;
}
if ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled() && !isset(self::$posixSignals[$signal]) && !(function_exists('posix_kill') && @posix_kill($this->getPid(), $signal))) {
if ($throwException) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild and posix_kill() is not available.');
}
return false;
}
if ('\\' === DIRECTORY_SEPARATOR) {
exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
if ($exitCode && $this->isRunning()) {
@ -1479,14 +1462,21 @@ class Process
return false;
}
}
if (true !== @proc_terminate($this->process, $signal) && '\\' !== DIRECTORY_SEPARATOR) {
if ($throwException) {
throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
} else {
if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) {
$ok = @proc_terminate($this->process, $signal);
} elseif (function_exists('posix_kill')) {
$ok = @posix_kill($this->getPid(), $signal);
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $this->getPid()), array(2 => array('pipe', 'w')), $pipes)) {
$ok = false === fgets($pipes[2]);
}
if (!$ok) {
if ($throwException) {
throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
}
return false;
return false;
}
}
$this->latestSignal = (int) $signal;

View File

@ -30,16 +30,18 @@ function handleSignal($signal)
break;
}
echo "received signal $name\n";
echo "signal $name\n";
}
declare (ticks = 1);
pcntl_signal(SIGTERM, 'handleSignal');
pcntl_signal(SIGINT, 'handleSignal');
echo 'received ';
$duration = isset($argv[1]) ? (int) $argv[1] : 3;
$start = microtime(true);
while ($duration > (microtime(true) - $start)) {
usleep(1000);
usleep(10000);
pcntl_signal_dispatch();
}

View File

@ -24,12 +24,23 @@ use Symfony\Component\Process\Process;
class ProcessTest extends \PHPUnit_Framework_TestCase
{
private static $phpBin;
private static $sigchild;
private static $notEnhancedSigchild = false;
public static function setUpBeforeClass()
{
$phpBin = new PhpExecutableFinder();
self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find();
if ('\\' !== DIRECTORY_SEPARATOR) {
// exec is mandatory to deal with sending a signal to the process
// see https://github.com/symfony/symfony/issues/5030 about prepending
// command with exec
self::$phpBin = 'exec '.self::$phpBin;
}
ob_start();
phpinfo(INFO_GENERAL);
self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
}
public function testThatProcessDoesNotThrowWarningDuringRun()
@ -78,20 +89,18 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testStopWithTimeoutIsActuallyWorking()
{
// exec is mandatory here since we send a signal to the process
// see https://github.com/symfony/symfony/issues/5030 about prepending
// command with exec
$p = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/NonStopableProcess.php 3');
$p = $this->getProcess(self::$phpBin.' '.__DIR__.'/NonStopableProcess.php 30');
$p->start();
usleep(100000);
$start = microtime(true);
$p->stop(1.1, SIGKILL);
while ($p->isRunning()) {
while (false === strpos($p->getOutput(), 'received')) {
usleep(1000);
}
$duration = microtime(true) - $start;
$start = microtime(true);
$p->stop(0.1);
$this->assertLessThan(4, $duration);
$p->wait();
$this->assertLessThan(15, microtime(true) - $start);
}
public function testAllOutputIsActuallyReadOnTermination()
@ -109,12 +118,16 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
$p->start();
// Let's wait enough time for process to finish...
// Here we don't call Process::run or Process::wait to avoid any read of pipes
usleep(500000);
if ($p->isRunning()) {
$this->markTestSkipped('Process execution did not complete in the required time frame');
// Don't call Process::run nor Process::wait to avoid any read of pipes
$h = new \ReflectionProperty($p, 'process');
$h->setAccessible(true);
$h = $h->getValue($p);
$s = proc_get_status($h);
while ($s['running']) {
usleep(1000);
$s = proc_get_status($h);
}
$o = $p->getOutput();
@ -124,18 +137,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testCallbacksAreExecutedWithStart()
{
$data = '';
$process = $this->getProcess('echo foo && '.self::$phpBin.' -r "sleep(1);" && echo foo');
$process = $this->getProcess('echo foo');
$process->start(function ($type, $buffer) use (&$data) {
$data .= $buffer;
});
while ($process->isRunning()) {
usleep(10000);
}
$process->wait();
$this->assertEquals(2, preg_match_all('/foo/', $data, $matches));
$this->assertSame('foo'.PHP_EOL, $data);
}
/**
@ -200,7 +209,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testSetInputWhileRunningThrowsAnException()
{
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
$process->start();
try {
$process->setInput('foobar');
@ -220,7 +229,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidInput($value)
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('foo');
$process->setInput($value);
}
@ -237,7 +246,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testValidInput($expected, $value)
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('foo');
$process->setInput($value);
$this->assertSame($expected, $process->getInput());
}
@ -473,7 +482,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testTTYCommand()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does have /dev/tty support');
$this->markTestSkipped('Windows does not have /dev/tty support');
}
$process = $this->getProcess('echo "foo" >> /dev/null && '.self::$phpBin.' -r "usleep(100000);"');
@ -585,12 +594,12 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
$process->start();
$end = microtime(true);
$this->assertLessThan(0.4, $end - $start);
$process->wait();
$process->stop();
}
public function testUpdateStatus()
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertTrue(strlen($process->getOutput()) > 0);
}
@ -599,7 +608,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
$this->assertNull($process->getExitCode());
$process->start();
$this->assertNull($process->getExitCode());
@ -611,7 +620,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
$process->run();
$this->assertEquals(0, $process->getExitCode());
$process->start();
@ -624,14 +633,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertSame(0, $process->getExitCode());
}
public function testStatus()
{
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
$this->assertFalse($process->isRunning());
$this->assertFalse($process->isStarted());
$this->assertFalse($process->isTerminated());
@ -650,7 +659,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testStop()
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(31);"');
$process->start();
$this->assertTrue($process->isRunning());
$process->stop();
@ -661,7 +670,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertTrue($process->isSuccessful());
}
@ -670,14 +679,12 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
$process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
$process->start();
$this->assertFalse($process->isSuccessful());
while ($process->isRunning()) {
usleep(300000);
}
$process->wait();
$this->assertTrue($process->isSuccessful());
}
@ -686,10 +693,8 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
{
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);throw new \Exception(\'BOUM\');"');
$process->start();
$this->assertTrue($process->isRunning());
$process->wait();
$process = $this->getProcess(self::$phpBin.' -r "throw new \Exception(\'BOUM\');"');
$process->run();
$this->assertFalse($process->isSuccessful());
}
@ -700,19 +705,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v');
$process->run();
$this->assertFalse($process->hasBeenSignaled());
}
public function testProcessWithoutTermSignalIsNotSignaled()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertFalse($process->hasBeenSignaled());
}
@ -724,7 +717,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertEquals(0, $process->getTermSignal());
}
@ -736,23 +729,10 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(32);"');
$process->start();
$process->stop();
$this->assertTrue($process->hasBeenSignaled());
}
public function testProcessWithTermSignal()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support POSIX signals');
}
$this->skipIfNotEnhancedSigchild();
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
$process->start();
$process->stop();
$this->assertEquals(15, $process->getTermSignal()); // SIGTERM
}
@ -767,11 +747,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
}
$this->skipIfNotEnhancedSigchild(false);
$termSignal = defined('SIGKILL') ? SIGKILL : 9;
$process = $this->getProcess('exec '.self::$phpBin.' -r "while (true) {}"');
$process = $this->getProcess(self::$phpBin.' -r "while (true) usleep(100);"');
$process->start();
posix_kill($process->getPid(), $termSignal);
posix_kill($process->getPid(), 9); // SIGKILL
$process->wait();
}
@ -796,12 +774,12 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
* @expectedExceptionMessage exceeded the timeout of 0.5 seconds.
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
*/
public function testRunProcessWithTimeout()
{
$timeout = 0.5;
$process = $this->getProcess(self::$phpBin.' -r "usleep(600000);"');
$timeout = 0.1;
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
$process->setTimeout($timeout);
$start = microtime(true);
try {
@ -822,25 +800,25 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testCheckTimeoutOnNonStartedProcess()
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
$process->checkTimeout();
$process = $this->getProcess('echo foo');
$this->assertNull($process->checkTimeout());
}
public function testCheckTimeoutOnTerminatedProcess()
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$process->checkTimeout();
$this->assertNull($process->checkTimeout());
}
/**
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
* @expectedExceptionMessage exceeded the timeout of 0.5 seconds.
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
*/
public function testCheckTimeoutOnStartedProcess()
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
$process->setTimeout(0.5);
$process = $this->getProcess(self::$phpBin.' -r "sleep(33);"');
$process->setTimeout(0.1);
$process->start();
$start = microtime(true);
@ -902,7 +880,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testStartAfterATimeout()
{
$process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }')));
$process = $this->getProcess(self::$phpBin.' -r "sleep(35);"');
$process->setTimeout(0.1);
try {
@ -910,30 +888,30 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
$this->fail('A RuntimeException should have been raised.');
} catch (RuntimeException $e) {
}
$this->assertFalse($process->isRunning());
$process->start();
usleep(1000);
$process->stop();
$process->stop(0);
throw $e;
}
public function testGetPid()
{
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(36);"');
$process->start();
$this->assertGreaterThan(0, $process->getPid());
$process->wait();
$process->stop(0);
}
public function testGetPidIsNullBeforeStart()
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
$process = $this->getProcess('foo');
$this->assertNull($process->getPid());
}
public function testGetPidIsNullAfterRun()
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('echo foo');
$process->run();
$this->assertNull($process->getPid());
}
@ -943,7 +921,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testSignal()
{
$process = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/SignalListener.php');
$process = $this->getProcess(self::$phpBin.' '.__DIR__.'/SignalListener.php');
$process->start();
while (false === strpos($process->getOutput(), 'Caught')) {
@ -982,7 +960,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testSignalProcessNotRunning()
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('foo');
$process->signal(1); // SIGHUP
}
@ -991,7 +969,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testMethodsThatNeedARunningProcess($method)
{
$process = $this->getProcess(self::$phpBin.' -v');
$process = $this->getProcess('foo');
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
$process->{$method}();
}
@ -1014,7 +992,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testMethodsThatNeedATerminatedProcess($method)
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(37);"');
$process->start();
try {
$process->{$method}();
@ -1038,31 +1016,33 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
}
/**
* @dataProvider provideWrongSignal
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongIntSignal()
public function testWrongSignal($signal)
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('POSIX signals do not work on Windows');
}
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
$process = $this->getProcess(self::$phpBin.' -r "sleep(38);"');
$process->start();
$process->signal(-4);
try {
$process->signal($signal);
$this->fail('A RuntimeException must have been thrown');
} catch (RuntimeException $e) {
$process->stop(0);
}
throw $e;
}
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
*/
public function testSignalWithWrongNonIntSignal()
public function provideWrongSignal()
{
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('POSIX signals do not work on Windows');
}
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
$process->start();
$process->signal('Céphalopodes');
return array(
array(-4),
array('Céphalopodes'),
);
}
public function testDisableOutputDisablesTheOutput()
@ -1185,7 +1165,7 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testStopTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(42);"');
$process->run(function () use ($process) {
$process->stop();
});
@ -1194,22 +1174,18 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
public function testKillSignalTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(43);"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(9); // SIGKILL
}
$process->signal(9); // SIGKILL
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
public function testTermSignalTerminatesProcessCleanly()
{
$process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"');
$process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(44);"');
$process->run(function () use ($process) {
if ($process->isRunning()) {
$process->signal(15); // SIGTERM
}
$process->signal(15); // SIGTERM
});
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
}
@ -1300,11 +1276,11 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
private function skipIfNotEnhancedSigchild($expectException = true)
{
if (self::$notEnhancedSigchild) {
if ($expectException) {
if (self::$sigchild) {
if (!$expectException) {
$this->markTestSkipped('PHP is compiled with --enable-sigchild.');
} elseif (self::$notEnhancedSigchild) {
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
} else {
$this->markTestSkipped('PHP is compiled with --enable-sigchild and enhanced mode is disabled.');
}
}
}

View File

@ -142,6 +142,7 @@ class PropertyPathBuilder
$this->elements[$offset + $i] = $path->getElement($pathOffset + $i);
$this->isIndex[$offset + $i] = $path->isIndex($pathOffset + $i);
}
ksort($this->elements);
}
/**

View File

@ -252,6 +252,17 @@ class PropertyPathBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($path, $builder->getPropertyPath());
}
public function testReplaceWithLongerPathKeepsOrder()
{
$path = new PropertyPath('new1.new2.new3');
$expected = new PropertyPath('new1.new2.new3.old2');
$builder = new PropertyPathBuilder(new PropertyPath('old1.old2'));
$builder->replace(0, 1, $path);
$this->assertEquals($expected, $builder->getPropertyPath());
}
public function testRemove()
{
$this->builder->remove(3);

View File

@ -85,6 +85,10 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
public function testDumpWithTooManyRoutes()
{
if (defined('HHVM_VERSION_ID')) {
$this->markTestSkipped('HHVM consumes too much memory on this test.');
}
$this->routeCollection->add('Test', new Route('/testing/{foo}'));
for ($i = 0; $i < 32769; ++$i) {
$this->routeCollection->add('route_'.$i, new Route('/route_'.$i));