Skip to content

Commit

Permalink
[Process] added unit tests, phpdoc, and reorganized methods from prev…
Browse files Browse the repository at this point in the history
…ious merge
  • Loading branch information
fabpot committed Oct 27, 2012
1 parent 41cb44b commit ef26a21
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
60 changes: 36 additions & 24 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -653,6 +653,42 @@ public function isRunning()
return $this->processInformation['running'];
}

/**
* Checks if the process has been started with no regard to the current state.
*
* @return Boolean true if status is ready, false otherwise
*/
public function isStarted()
{
return $this->status != self::STATUS_READY;
}

/**
* Checks if the process is terminated.
*
* @return Boolean true if process is terminated, false otherwise
*/
public function isTerminated()
{
$this->updateStatus();

return $this->status == self::STATUS_TERMINATED;
}

/**
* Gets the process status.
*
* The status is one of: ready, started, terminated.
*
* @return string The current process status
*/
public function getStatus()
{
$this->updateStatus();

return $this->status;
}

/**
* Stops the process.
*
Expand Down Expand Up @@ -927,30 +963,6 @@ public function setEnhanceSigchildCompatibility($enhance)
return $this;
}

public function getStatus()
{
$this->updateStatus();

return $this->status;
}

/**
* Checks if the process has been started with no regard to current state.
*
* @return Boolean true if status is started or terminated, false otherwise
*/
public function isStarted()
{
return $this->status != self::STATUS_READY;
}

public function isTerminated()
{
$this->updateStatus();

return $this->status == self::STATUS_TERMINATED;
}

/**
* Builds up the callback used by wait().
*
Expand Down
15 changes: 12 additions & 3 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Expand Up @@ -126,7 +126,7 @@ public function testGetIncrementalErrorOutput()
$p = new Process(sprintf('php -r %s', escapeshellarg('ini_set(\'display_errors\',\'on\');usleep(50000);$n=0;while($n<3){echo $a;$n++;}')));

$p->start();
while($p->isRunning()) {
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/PHP Notice/', $p->getIncrementalOutput(), $matches));
usleep(20000);
}
Expand All @@ -145,7 +145,7 @@ public function testGetIncrementalOutput()
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while($n<3){echo \' foo \';usleep(50000);$n++;}')));

$p->start();
while($p->isRunning()) {
while ($p->isRunning()) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
usleep(20000);
}
Expand Down Expand Up @@ -198,14 +198,23 @@ public function testGetExitCode()
$this->assertEquals(0, $process->getExitCode());
}

public function testIsRunning()
public function testStatus()
{
$process = $this->getProcess('php -r "sleep(1);"');
$this->assertFalse($process->isRunning());
$this->assertFalse($process->isStarted());
$this->assertFalse($process->isTerminated());
$this->assertSame(Process::STATUS_READY, $process->getStatus());
$process->start();
$this->assertTrue($process->isRunning());
$this->assertTrue($process->isStarted());
$this->assertFalse($process->isTerminated());
$this->assertSame(Process::STATUS_STARTED, $process->getStatus());
$process->wait();
$this->assertFalse($process->isRunning());
$this->assertTrue($process->isStarted());
$this->assertTrue($process->isTerminated());
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
}

public function testStop()
Expand Down

0 comments on commit ef26a21

Please sign in to comment.