Skip to content

Commit

Permalink
Removed wait method - wasn't working - to be added
Browse files Browse the repository at this point in the history
  • Loading branch information
sushilkg committed Sep 1, 2018
1 parent 735294c commit 304f148
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/Helper/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function closePipes()
fclose($this->pipes[self::STDERR_DESCRIPTOR_KEY]);
}

public function execute(bool $blocking = false)
public function execute()
{
if ($this->isRunning()) {
throw new RuntimeException('Process is already running');
Expand All @@ -91,10 +91,6 @@ public function execute(bool $blocking = false)
$this->updateStatus();

$this->startTime = microtime(true);

if ($blocking) {
$this->wait();
}
}

public function getOutput()
Expand All @@ -112,29 +108,15 @@ public function getExitCode()
return $this->status['exitcode'];
}

public function checkTimeout()
{
if ($this->timeout && $this->timeout < microtime(true) - $this->startTime) {
$this->stop();
}

return $this->status;
}

public function wait()
public function isRunning()
{
while ($this->isRunning()) {
usleep(1000);
$this->checkTimeout();
$this->updateStatus();
if(!$this->status) {
return false;
}

return $this->status;
}
$this->updateStatus();

public function isRunning()
{
return $this->status && $this->status['running'];
return $this->status['running'];
}

public function getProcessId()
Expand Down
10 changes: 10 additions & 0 deletions tests/Helper/ShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ public function test_get_output()
$shell->execute();
$this->assertSame("hello\n", $shell->getOutput());
}

public function test_get_process_id()
{
$shell = new Shell("echo hello");
$shell->execute();
echo '<pre>';
print_r($shell->getProcessId());
exit;
$this->assertInternalType("int", $shell->getProcessId());
}
}

0 comments on commit 304f148

Please sign in to comment.