Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 261eae9

Browse files
alexbowersfabpot
authored andcommitted
Added deprecation to cwd not existing Fixes #18249
1 parent 30e3b6d commit 261eae9

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

UPGRADE-3.4.md

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

213+
* Calling `Process::start()` without setting a valid working directory (via `setWorkingDirectory()` or constructor) beforehand is deprecated and will throw an exception in 4.0.
214+
213215
Profiler
214216
--------
215217

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ Ldap
567567
Process
568568
-------
569569

570+
* Passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is not supported anymore.
571+
570572
* The `Symfony\Component\Process\ProcessBuilder` class has been removed,
571573
use the `Symfony\Component\Process\Process` class directly instead.
572574

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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ public function start(callable $callback = null/*, array $env = array()*/)
334334
$ptsWorkaround = fopen(__FILE__, 'r');
335335
}
336336

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

339347
foreach ($envBackup as $k => $v) {
@@ -831,7 +839,7 @@ public function isRunning()
831839
*/
832840
public function isStarted()
833841
{
834-
return $this->status != self::STATUS_READY;
842+
return self::STATUS_READY != $this->status;
835843
}
836844

837845
/**
@@ -843,7 +851,7 @@ public function isTerminated()
843851
{
844852
$this->updateStatus(false);
845853

846-
return $this->status == self::STATUS_TERMINATED;
854+
return self::STATUS_TERMINATED == $this->status;
847855
}
848856

849857
/**
@@ -1322,7 +1330,7 @@ public function areEnvironmentVariablesInherited()
13221330
*/
13231331
public function checkTimeout()
13241332
{
1325-
if ($this->status !== self::STATUS_STARTED) {
1333+
if (self::STATUS_STARTED !== $this->status) {
13261334
return;
13271335
}
13281336

@@ -1513,7 +1521,7 @@ private function readPipes($blocking, $close)
15131521
$callback = $this->callback;
15141522
foreach ($result as $type => $data) {
15151523
if (3 !== $type) {
1516-
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
1524+
$callback(self::STDOUT === $type ? self::OUT : self::ERR, $data);
15171525
} elseif (!isset($this->fallbackStatus['signaled'])) {
15181526
$this->fallbackStatus['exitcode'] = (int) $data;
15191527
}

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

Lines changed: 42 additions & 2 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) {
@@ -313,7 +353,7 @@ public function testCallbackIsExecutedForOutput()
313353

314354
$called = false;
315355
$p->run(function ($type, $buffer) use (&$called) {
316-
$called = $buffer === 'foo';
356+
$called = 'foo' === $buffer;
317357
});
318358

319359
$this->assertTrue($called, 'The callback should be executed with the output');
@@ -326,7 +366,7 @@ public function testCallbackIsExecutedForOutputWheneverOutputIsDisabled()
326366

327367
$called = false;
328368
$p->run(function ($type, $buffer) use (&$called) {
329-
$called = $buffer === 'foo';
369+
$called = 'foo' === $buffer;
330370
});
331371

332372
$this->assertTrue($called, 'The callback should be executed with the output');

0 commit comments

Comments
 (0)