diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 455d6b24f80d..f9cfd5bd8974 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -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. * @@ -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(). * diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index a3364cc8d6ac..23717719f82f 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -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); } @@ -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); } @@ -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()