diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 763e45285e..a8dc19791f 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -300,6 +300,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 11e7cdfe92..20df7ec98f 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -639,6 +639,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 7193c498d4..c5cdb99441 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 f1f7d30f8a..2a73814d77 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -332,6 +332,14 @@ class Process implements \IteratorAggregate $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) { diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index d939604750..1ad601c715 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -48,6 +48,46 @@ class ProcessTest extends TestCase } } + /** + * @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) {