diff --git a/src/Symfony/Component/Process/ExecutableFinder.php b/src/Symfony/Component/Process/ExecutableFinder.php index 087c94b0f2..5cc99c7692 100644 --- a/src/Symfony/Component/Process/ExecutableFinder.php +++ b/src/Symfony/Component/Process/ExecutableFinder.php @@ -19,22 +19,23 @@ namespace Symfony\Component\Process; */ 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 @@ class ExecutableFinder } 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; } } diff --git a/src/Symfony/Component/Process/PhpProcess.php b/src/Symfony/Component/Process/PhpProcess.php index 5db6e134e2..7a9fd0864b 100644 --- a/src/Symfony/Component/Process/PhpProcess.php +++ b/src/Symfony/Component/Process/PhpProcess.php @@ -66,6 +66,6 @@ class PhpProcess extends Process $this->setCommandLine($php); } - return parent::start($callback); + parent::start($callback); } } diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 3ada4400e1..4af26e85a2 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -159,8 +159,8 @@ class Process * 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 @@ class Process * 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 @@ class Process * 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 @@ class Process * * @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 @@ class Process * * @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 @@ class Process /** * 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 @@ class Process * 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,6 +865,9 @@ class Process } } + /** + * Updates the current error output of the process (STDERR). + */ protected function updateErrorOutput() { if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) { @@ -877,6 +875,9 @@ class Process } } + /** + * 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])) { diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 8cb9e4ad26..a5a3376f72 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -16,8 +16,6 @@ namespace Symfony\Component\Process\Tests; */ 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 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase 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()); } diff --git a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index 4a321adf55..67fc0025bd 100644 --- a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php @@ -13,15 +13,6 @@ namespace Symfony\Component\Process\Tests; 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 @@ class SigchildDisabledProcessTest extends AbstractProcessTest { 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; + } } diff --git a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php index 4c04ff146b..fb9b6f8cc8 100644 --- a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php @@ -13,15 +13,6 @@ namespace Symfony\Component\Process\Tests; 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 @@ class SigchildEnabledProcessTest extends AbstractProcessTest $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; + } } diff --git a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php index 8742a69e54..17dea3fe54 100644 --- a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php @@ -15,20 +15,14 @@ use Symfony\Component\Process\Process; 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 @@ class SimpleProcessTest extends AbstractProcessTest $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'); + } + } }