merged branch romainneutron/properties-reset (PR #8806)

This PR was merged into the 2.2 branch.

Discussion
----------

[2.2][Process] Use a consistent way to reset data of the process latest run

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT

It is actually useful when cloning or running again a process.

Commits
-------

0723c10 [Process] Use a consistent way to reset data of the process latest run
This commit is contained in:
Fabien Potencier 2013-08-21 09:09:53 +02:00
commit 36b5d19d9d
3 changed files with 60 additions and 15 deletions

View File

@ -165,17 +165,7 @@ class Process
public function __clone()
{
$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->resetProcessData();
}
/**
@ -231,11 +221,8 @@ class Process
throw new RuntimeException('Process is already running');
}
$this->resetProcessData();
$this->starttime = microtime(true);
$this->stdout = '';
$this->stderr = '';
$this->incrementalOutputOffset = 0;
$this->incrementalErrorOutputOffset = 0;
$this->callback = $this->buildCallback($callback);
//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;
}
}

View File

@ -235,6 +235,27 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$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()
{
$process = $this->getProcess('php -m');

View File

@ -21,6 +21,22 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
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
*/