Skip to content

Commit

Permalink
Merge pull request #342 from OndraM/symfony-process
Browse files Browse the repository at this point in the history
Use Symfony Process component to start local webdriver processes
  • Loading branch information
OndraM committed Nov 2, 2016
2 parents 6cc5a50 + e8a8993 commit f694c8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"require": {
"php": "^5.5 || ~7.0",
"symfony/process": "^2.8 || ^3.1",
"ext-curl": "*"
},
"require-dev": {
Expand Down
32 changes: 15 additions & 17 deletions lib/Remote/Service/DriverService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

use Exception;
use Facebook\WebDriver\Net\URLChecker;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

/**
* Start local WebDriver service (when remote WebDriver server is not used).
*/
class DriverService
{
/**
Expand All @@ -41,7 +46,7 @@ class DriverService
private $environment;

/**
* @var resource
* @var Process
*/
private $process;

Expand Down Expand Up @@ -76,18 +81,13 @@ public function start()
return $this;
}

$pipes = [];
$this->process = proc_open(
sprintf('%s %s', $this->executable, implode(' ', $this->args)),
$descriptorspec = [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
2 => ['pipe', 'a'], // stderr
],
$pipes,
null,
$this->environment
);
$processBuilder = (new ProcessBuilder())
->setPrefix($this->executable)
->setArguments($this->args)
->addEnvironmentVariables($this->environment);

$this->process = $processBuilder->getProcess();
$this->process->start();

$checker = new URLChecker();
$checker->waitUntilAvailable(20 * 1000, $this->url . '/status');
Expand All @@ -104,7 +104,7 @@ public function stop()
return $this;
}

proc_terminate($this->process);
$this->process->stop();
$this->process = null;

$checker = new URLChecker();
Expand All @@ -122,9 +122,7 @@ public function isRunning()
return false;
}

$status = proc_get_status($this->process);

return $status['running'];
return $this->process->isRunning();
}

/**
Expand Down

0 comments on commit f694c8e

Please sign in to comment.