diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 2c80252b5b8ab..9ad662ffed825 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -210,6 +210,8 @@ Process * The `Symfony\Component\Process\ProcessBuilder` class has been deprecated, use the `Symfony\Component\Process\Process` class directly instead. + * Calling `Process::start()` without setting a valid working directory (via `setWorkingDirectory()` or constructor) beforehand is deprecated and will throw an exception in 4.0. + Profiler -------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 9f8017c47e8a4..59f4607863ad1 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -567,6 +567,8 @@ Ldap Process ------- + * Passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is not supported anymore. + * The `Symfony\Component\Process\ProcessBuilder` class has been removed, use the `Symfony\Component\Process\Process` class directly instead. diff --git a/src/Symfony/Component/Process/CHANGELOG.md b/src/Symfony/Component/Process/CHANGELOG.md index 7193c498d4326..c5cdb9944164b 100644 --- a/src/Symfony/Component/Process/CHANGELOG.md +++ b/src/Symfony/Component/Process/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * deprecated the ProcessBuilder class + * deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor) 3.3.0 ----- diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index e925e913863a9..79cb20cb66ebd 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -334,6 +334,14 @@ public function start(callable $callback = null/*, array $env = array()*/) $ptsWorkaround = fopen(__FILE__, 'r'); } + if (!is_dir($this->cwd)) { + if ('\\' === DIRECTORY_SEPARATOR) { + throw new RuntimeException('The provided cwd does not exist.'); + } + + @trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since version 3.4 and will be removed in 4.0.', E_USER_DEPRECATED); + } + $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options); foreach ($envBackup as $k => $v) { @@ -831,7 +839,7 @@ public function isRunning() */ public function isStarted() { - return $this->status != self::STATUS_READY; + return self::STATUS_READY != $this->status; } /** @@ -843,7 +851,7 @@ public function isTerminated() { $this->updateStatus(false); - return $this->status == self::STATUS_TERMINATED; + return self::STATUS_TERMINATED == $this->status; } /** @@ -1322,7 +1330,7 @@ public function areEnvironmentVariablesInherited() */ public function checkTimeout() { - if ($this->status !== self::STATUS_STARTED) { + if (self::STATUS_STARTED !== $this->status) { return; } @@ -1513,7 +1521,7 @@ private function readPipes($blocking, $close) $callback = $this->callback; foreach ($result as $type => $data) { if (3 !== $type) { - $callback($type === self::STDOUT ? self::OUT : self::ERR, $data); + $callback(self::STDOUT === $type ? self::OUT : self::ERR, $data); } elseif (!isset($this->fallbackStatus['signaled'])) { $this->fallbackStatus['exitcode'] = (int) $data; } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 267257117d43d..1ad601c715aaf 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -48,6 +48,46 @@ protected function tearDown() } } + /** + * @group legacy + * @expectedDeprecation The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since version 3.4 and will be removed in 4.0. + */ + public function testInvalidCwd() + { + if ('\\' === DIRECTORY_SEPARATOR) { + $this->markTestSkipped('Windows handles this automatically.'); + } + + // Check that it works fine if the CWD exists + $cmd = new Process('echo test', __DIR__); + $cmd->run(); + + $cmd = new Process('echo test', __DIR__.'/notfound/'); + $cmd->run(); + } + + /** + * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage The provided cwd does not exist. + */ + public function testInvalidCwdOnWindows() + { + if ('\\' !== DIRECTORY_SEPARATOR) { + $this->markTestSkipped('Unix handles this automatically.'); + } + + try { + // Check that it works fine if the CWD exists + $cmd = new Process('echo test', __DIR__); + $cmd->run(); + } catch (\Exception $e) { + $this->fail($e); + } + + $cmd = new Process('echo test', __DIR__.'/notfound/'); + $cmd->run(); + } + public function testThatProcessDoesNotThrowWarningDuringRun() { if ('\\' === DIRECTORY_SEPARATOR) { @@ -313,7 +353,7 @@ public function testCallbackIsExecutedForOutput() $called = false; $p->run(function ($type, $buffer) use (&$called) { - $called = $buffer === 'foo'; + $called = 'foo' === $buffer; }); $this->assertTrue($called, 'The callback should be executed with the output'); @@ -326,7 +366,7 @@ public function testCallbackIsExecutedForOutputWheneverOutputIsDisabled() $called = false; $p->run(function ($type, $buffer) use (&$called) { - $called = $buffer === 'foo'; + $called = 'foo' === $buffer; }); $this->assertTrue($called, 'The callback should be executed with the output');
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: