[Process] Use a consistent way to reset data of the process latest run
It is actually useful when cloning or running again a process.
This commit is contained in:
parent
d60fa064f3
commit
0723c10239
@ -165,17 +165,7 @@ class Process
|
|||||||
|
|
||||||
public function __clone()
|
public function __clone()
|
||||||
{
|
{
|
||||||
$this->callback = null;
|
$this->resetProcessData();
|
||||||
$this->exitcode = null;
|
|
||||||
$this->fallbackExitcode = null;
|
|
||||||
$this->processInformation = null;
|
|
||||||
$this->stdout = null;
|
|
||||||
$this->stderr = null;
|
|
||||||
$this->pipes = null;
|
|
||||||
$this->process = null;
|
|
||||||
$this->status = self::STATUS_READY;
|
|
||||||
$this->fileHandles = null;
|
|
||||||
$this->readBytes = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,11 +221,8 @@ class Process
|
|||||||
throw new RuntimeException('Process is already running');
|
throw new RuntimeException('Process is already running');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->resetProcessData();
|
||||||
$this->starttime = microtime(true);
|
$this->starttime = microtime(true);
|
||||||
$this->stdout = '';
|
|
||||||
$this->stderr = '';
|
|
||||||
$this->incrementalOutputOffset = 0;
|
|
||||||
$this->incrementalErrorOutputOffset = 0;
|
|
||||||
$this->callback = $this->buildCallback($callback);
|
$this->callback = $this->buildCallback($callback);
|
||||||
|
|
||||||
//Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
|
//Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
|
||||||
@ -1154,4 +1141,25 @@ class Process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets data related to the latest run of the process.
|
||||||
|
*/
|
||||||
|
private function resetProcessData()
|
||||||
|
{
|
||||||
|
$this->starttime = null;
|
||||||
|
$this->callback = null;
|
||||||
|
$this->exitcode = null;
|
||||||
|
$this->fallbackExitcode = null;
|
||||||
|
$this->processInformation = null;
|
||||||
|
$this->stdout = null;
|
||||||
|
$this->stderr = null;
|
||||||
|
$this->pipes = null;
|
||||||
|
$this->process = null;
|
||||||
|
$this->status = self::STATUS_READY;
|
||||||
|
$this->fileHandles = null;
|
||||||
|
$this->readBytes = null;
|
||||||
|
$this->incrementalOutputOffset = 0;
|
||||||
|
$this->incrementalErrorOutputOffset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,27 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue(strlen($process->getOutput()) > 0);
|
$this->assertTrue(strlen($process->getOutput()) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetExitCodeIsNullOnStart()
|
||||||
|
{
|
||||||
|
$process = $this->getProcess('php -r "usleep(200000);"');
|
||||||
|
$this->assertNull($process->getExitCode());
|
||||||
|
$process->start();
|
||||||
|
$this->assertNull($process->getExitCode());
|
||||||
|
$process->wait();
|
||||||
|
$this->assertEquals(0, $process->getExitCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExitCodeIsNullOnWhenStartingAgain()
|
||||||
|
{
|
||||||
|
$process = $this->getProcess('php -r "usleep(200000);"');
|
||||||
|
$process->run();
|
||||||
|
$this->assertEquals(0, $process->getExitCode());
|
||||||
|
$process->start();
|
||||||
|
$this->assertNull($process->getExitCode());
|
||||||
|
$process->wait();
|
||||||
|
$this->assertEquals(0, $process->getExitCode());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetExitCode()
|
public function testGetExitCode()
|
||||||
{
|
{
|
||||||
$process = $this->getProcess('php -m');
|
$process = $this->getProcess('php -m');
|
||||||
|
@ -21,6 +21,22 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
|
|||||||
parent::testGetExitCode();
|
parent::testGetExitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
||||||
|
*/
|
||||||
|
public function testGetExitCodeIsNullOnStart()
|
||||||
|
{
|
||||||
|
parent::testGetExitCodeIsNullOnStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
||||||
|
*/
|
||||||
|
public function testGetExitCodeIsNullOnWhenStartingAgain()
|
||||||
|
{
|
||||||
|
parent::testGetExitCodeIsNullOnWhenStartingAgain();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user