8000 feature #23708 Added deprecation to cwd not existing Fixes #18249 (al… · symfony/symfony@87712e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87712e4

Browse files
committed
feature #23708 Added deprecation to cwd not existing Fixes #18249 (alexbowers)
This PR was squashed before being merged into the 3.4 branch (closes #23708). Discussion ---------- Added deprecation to cwd not existing Fixes #18249 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? |no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #18249 | License | MIT | Doc PR | - Commits ------- 261eae9 Added deprecation to cwd not existing Fixes #18249
2 parents 855971a + 261eae9 commit 87712e4

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

UPGRADE-3.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ Process
300300
* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
301301
use the `Symfony\Component\Process\Process` class directly instead.
302302

303+
* Calling `Process::start()` without setting a valid working directory (via `setWorkingDirectory()` or constructor) beforehand is deprecated and will throw an exception in 4.0.
304+
303305
Profiler
304306
--------
305307

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ Ldap
639639
Process
640640
-------
641641

642+
* Passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is not supported anymore.
643+
642644
* The `Symfony\Component\Process\ProcessBuilder` class has been removed,
643645
use the `Symfony\Component\Process\Process` class directly instead.
644646

src/Symfony/Component/Process/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated the ProcessBuilder class
8+
* deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor)
89

910
3.3.0
1011
-----

src/Symfony/Component/Process/Process.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ public function start(callable $callback = null/*, array $env = array()*/)
332332
$ptsWorkaround = fopen(__FILE__, 'r');
333333
}
334334

335+
if (!is_dir($this->cwd)) {
336+
if ('\\' === DIRECTORY_SEPARATOR) {
337+
throw new RuntimeException('The provided cwd does not exist.');
338+
}
339+
340+
@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);
341+
}
342+
335343
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
336344

337345
foreach ($envBackup as $k => $v) {

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,46 @@ protected function tearDown()
4848
}
4949
}
5050

51+
/**
52+
* @group legacy
53+
* @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.
54+
*/
55+
public function testInvalidCwd()
56+
{
57+
if ('\\' === DIRECTORY_SEPARATOR) {
58+
$this->markTestSkipped('Windows handles this automatically.');
59+
}
60+
61+
// Check that it works fine if the CWD exists
62+
$cmd = new Process('echo test', __DIR__);
63+
$cmd->run();
64+
65+
$cmd = new Process('echo test', __DIR__.'/notfound/');
66+
$cmd->run();
67+
}
68+
69+
/**
70+
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
71+
* @expectedExceptionMessage The provided cwd does not exist.
72+
*/
73+
public function testInvalidCwdOnWindows()
74+
{
75+
if ('\\' !== DIRECTORY_SEPARATOR) {
76+
$this->markTestSkipped('Unix handles this automatically.');
77+
}
78+
79+
try {
80+
// Check that it works fine if the CWD exists
81+
$cmd = new Process('echo test', __DIR__);
82+
$cmd->run();
83+
} catch (\Exception $e) {
84+
$this->fail($e);
85+
}
86+
87+
$cmd = new Process('echo test', __DIR__.'/notfound/');
88+
$cmd->run();
89+
}
90+
5191
public function testThatProcessDoesNotThrowWarningDuringRun()
5292
{
5393
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
0