Browse files

[Process] Fix docblocks, remove `return` from `PhpProcess#start()` as…

… parent returns nothing, cleaned up `ExecutableFinder`
  • Loading branch information...
1 parent 78002b9 commit fa405bdcf3a01d90887bee1c480531e50ea83ec3 @stloyd stloyd committed Jan 8, 2013
View
21 ExecutableFinder.php
@@ -19,22 +19,23 @@
*/
class ExecutableFinder
{
- private static $isWindows;
-
private $suffixes = array('.exe', '.bat', '.cmd', '.com');
- public function __construct()
- {
- if (null === self::$isWindows) {
- self::$isWindows = 0 === stripos(PHP_OS, 'win');
- }
- }
-
+ /**
+ * Replaces default suffixes of executable.
+ *
+ * @param array $suffixes
+ */
public function setSuffixes(array $suffixes)
{
$this->suffixes = $suffixes;
}
+ /**
+ * Adds new possible suffix to check for executable.
+ *
+ * @param string $suffix
+ */
public function addSuffix($suffix)
{
$this->suffixes[] = $suffix;
@@ -78,7 +79,7 @@ public function find($name, $default = null, array $extraDirs = array())
}
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
- if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (self::$isWindows || is_executable($file))) {
+ if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
return $file;
}
}
View
2 PhpProcess.php
@@ -66,6 +66,6 @@ public function start($callback = null)
$this->setCommandLine($php);
}
- return parent::start($callback);
+ parent::start($callback);
}
}
View
33 Process.php
@@ -159,8 +159,8 @@ public function __destruct()
* The STDOUT and STDERR are also available after the process is finished
* via the getOutput() and getErrorOutput() methods.
*
- * @param Closure|string|array $callback A PHP callback to run whenever there is some
- * output available on STDOUT or STDERR
+ * @param callback|null $callback A PHP callback to run whenever there is some
+ * output available on STDOUT or STDERR
*
* @return integer The exit status code
*
@@ -190,8 +190,8 @@ public function run($callback = null)
* with true as a second parameter then the callback will get all data occurred
* in (and since) the start call.
*
- * @param Closure|string|array $callback A PHP callback to run whenever there is some
- * output available on STDOUT or STDERR
+ * @param callback|null $callback A PHP callback to run whenever there is some
+ * output available on STDOUT or STDERR
*
* @throws \RuntimeException When process can't be launch or is stopped
* @throws \RuntimeException When process is already running
@@ -318,11 +318,12 @@ public function start($callback = null)
* from the output in real-time while writing the standard input to the process.
* It allows to have feedback from the independent process during execution.
*
- * @param mixed $callback A valid PHP callback
+ * @param callback|null $callback A valid PHP callback
*
- * @return int The exitcode of the process
+ * @return integer The exitcode of the process
*
- * @throws \RuntimeException
+ * @throws \RuntimeException When process timed out
+ * @throws \RuntimeException When process stopped after receiving signal
*/
public function wait($callback = null)
{
@@ -455,8 +456,6 @@ public function getExitCode()
*
* @return string A string representation for the exit status code
*
- * @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
- *
* @see http://tldp.org/LDP/abs/html/exitcodes.html
* @see http://en.wikipedia.org/wiki/Unix_signal
*/
@@ -472,8 +471,6 @@ public function getExitCodeText()
*
* @return Boolean true if the process ended successfully, false otherwise
*
- * @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
- *
* @api
*/
public function isSuccessful()
@@ -576,11 +573,9 @@ public function isRunning()
/**
* Stops the process.
*
- * @param float $timeout The timeout in seconds
+ * @param integer|float $timeout The timeout in seconds
*
* @return integer The exit-code of the process
- *
- * @throws \RuntimeException if the process got signaled
*/
public function stop($timeout=10)
{
@@ -828,9 +823,9 @@ public function setEnhanceSigchildCompatibility($enhance)
* The callbacks adds all occurred output to the specific buffer and calls
* the user callback (if present) with the received output.
*
- * @param mixed $callback The user defined PHP callback
+ * @param callback|null $callback The user defined PHP callback
*
- * @return mixed A PHP callable
+ * @return callback A PHP callable
*/
protected function buildCallback($callback)
{
@@ -870,13 +865,19 @@ protected function updateStatus()
}
}
+ /**
+ * Updates the current error output of the process (STDERR).
+ */
protected function updateErrorOutput()
{
if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
$this->addErrorOutput(stream_get_contents($this->pipes[self::STDERR]));
}
}
+ /**
+ * Updates the current output of the process (STDOUT).
+ */
protected function updateOutput()
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && isset($this->fileHandles[self::STDOUT]) && is_resource($this->fileHandles[self::STDOUT])) {
View
14 Tests/AbstractProcessTest.php
@@ -16,8 +16,6 @@
*/
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{
- abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
-
/**
* @expectedException \InvalidArgumentException
*/
@@ -300,4 +298,16 @@ public function methodProvider()
return $defaults;
}
+
+ /**
+ * @param string $commandline
+ * @param null $cwd
+ * @param array $env
+ * @param null $stdin
+ * @param integer $timeout
+ * @param array $options
+ *
+ * @return \Symfony\Component\Process\Process
+ */
+ abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
}
View
20 Tests/SigchildDisabledProcessTest.php
@@ -13,15 +13,6 @@
class SigchildDisabledProcessTest extends AbstractProcessTest
{
-
- protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
- {
- $process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
- $process->setEnhanceSigchildCompatibility(false);
-
- return $process;
- }
-
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
@@ -96,4 +87,15 @@ public function testIsNotSuccessful()
{
parent::testIsNotSuccessful();
}
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
+ {
+ $process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
+ $process->setEnhanceSigchildCompatibility(false);
+
+ return $process;
+ }
}
View
19 Tests/SigchildEnabledProcessTest.php
@@ -13,15 +13,6 @@
class SigchildEnabledProcessTest extends AbstractProcessTest
{
-
- protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
- {
- $process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
- $process->setEnhanceSigchildCompatibility(true);
-
- return $process;
- }
-
/**
* @expectedException Symfony\Component\Process\Exception\RuntimeException
*/
@@ -62,4 +53,14 @@ public function testExitCodeText()
$this->assertInternalType('string', $process->getExitCodeText());
}
+ /**
+ * {@inheritdoc}
+ */
+ protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
+ {
+ $process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
+ $process->setEnhanceSigchildCompatibility(true);
+
+ return $process;
+ }
}
View
27 Tests/SimpleProcessTest.php
@@ -15,20 +15,14 @@
class SimpleProcessTest extends AbstractProcessTest
{
+ private $enabledSigchild = false;
- protected function skipIfPHPSigchild()
+ public function setUp()
{
ob_start();
phpinfo(INFO_GENERAL);
- if (false !== strpos(ob_get_clean(), '--enable-sigchild')) {
- $this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed');
- }
- }
-
- protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
- {
- return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
+ $this->enabledSigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
}
public function testGetExitCode()
@@ -84,4 +78,19 @@ public function testIsNotSuccessful()
$this->skipIfPHPSigchild();
parent::testIsNotSuccessful();
}
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
+ {
+ return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
+ }
+
+ private function skipIfPHPSigchild()
+ {
+ if ($this->enabledSigchild) {
+ $this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed');
+ }
+ }
}

0 comments on commit fa405bd

Please sign in to comment.