Skip to content

Commit ef26a21

Browse files
committed
[Process] added unit tests, phpdoc, and reorganized methods from previous merge
1 parent 41cb44b commit ef26a21

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,42 @@ public function isRunning()
653653
return $this->processInformation['running'];
654654
}
655655

656+
/**
657+
* Checks if the process has been started with no regard to the current state.
658+
*
659+
* @return Boolean true if status is ready, false otherwise
660+
*/
661+
public function isStarted()
662+
{
663+
return $this->status != self::STATUS_READY;
664+
}
665+
666+
/**
667+
* Checks if the process is terminated.
668+
*
669+
* @return Boolean true if process is terminated, false otherwise
670+
*/
671+
public function isTerminated()
672+
{
673+
$this->updateStatus();
674+
675+
return $this->status == self::STATUS_TERMINATED;
676+
}
677+
678+
/**
679+
* Gets the process status.
680+
*
681+
* The status is one of: ready, started, terminated.
682+
*
683+
* @return string The current process status
684+
*/
685+
public function getStatus()
686+
{
687+
$this->updateStatus();
688+
689+
return $this->status;
690+
}
691+
656692
/**
657693
* Stops the process.
658694
*
@@ -927,30 +963,6 @@ public function setEnhanceSigchildCompatibility($enhance)
927963
return $this;
928964
}
929965

930-
public function getStatus()
931-
{
932-
$this->updateStatus();
933-
934-
return $this->status;
935-
}
936-
937-
/**
938-
* Checks if the process has been started with no regard to current state.
939-
*
940-
* @return Boolean true if status is started or terminated, false otherwise
941-
*/
942-
public function isStarted()
943-
{
944-
return $this->status != self::STATUS_READY;
945-
}
946-
947-
public function isTerminated()
948-
{
949-
$this->updateStatus();
950-
951-
return $this->status == self::STATUS_TERMINATED;
952-
}
953-
954966
/**
955967
* Builds up the callback used by wait().
956968
*

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testGetIncrementalErrorOutput()
126126
$p = new Process(sprintf('php -r %s', escapeshellarg('ini_set(\'display_errors\',\'on\');usleep(50000);$n=0;while($n<3){echo $a;$n++;}')));
127127

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

147147
$p->start();
148-
while($p->isRunning()) {
148+
while ($p->isRunning()) {
149149
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
150150
usleep(20000);
151151
}
@@ -198,14 +198,23 @@ public function testGetExitCode()
198198
$this->assertEquals(0, $process->getExitCode());
199199
}
200200

201-
public function testIsRunning()
201+
public function testStatus()
202202
{
203203
$process = $this->getProcess('php -r "sleep(1);"');
204204
$this->assertFalse($process->isRunning());
205+
$this->assertFalse($process->isStarted());
206+
$this->assertFalse($process->isTerminated());
207+
$this->assertSame(Process::STATUS_READY, $process->getStatus());
205208
$process->start();
206209
$this->assertTrue($process->isRunning());
210+
$this->assertTrue($process->isStarted());
211+
$this->assertFalse($process->isTerminated());
212+
$this->assertSame(Process::STATUS_STARTED, $process->getStatus());
207213
$process->wait();
208214
$this->assertFalse($process->isRunning());
215+
$this->assertTrue($process->isStarted());
216+
$this->assertTrue($process->isTerminated());
217+
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
209218
}
210219

211220
public function testStop()

0 commit comments

Comments
 (0)