Added deprecation to cwd not existing Fixes #18249

This commit is contained in:
Alex Bowers 2017-07-28 22:09:12 +01:00 committed by Fabien Potencier
parent 30e3b6d27e
commit 261eae970f
5 changed files with 59 additions and 6 deletions

View File

@ -210,6 +210,8 @@ Process
* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated, * The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead. 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 Profiler
-------- --------

View File

@ -567,6 +567,8 @@ Ldap
Process 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, * The `Symfony\Component\Process\ProcessBuilder` class has been removed,
use the `Symfony\Component\Process\Process` class directly instead. use the `Symfony\Component\Process\Process` class directly instead.

View File

@ -5,6 +5,7 @@ CHANGELOG
----- -----
* deprecated the ProcessBuilder class * deprecated the ProcessBuilder class
* deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor)
3.3.0 3.3.0
----- -----

View File

@ -334,6 +334,14 @@ class Process implements \IteratorAggregate
$ptsWorkaround = fopen(__FILE__, 'r'); $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); $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
foreach ($envBackup as $k => $v) { foreach ($envBackup as $k => $v) {
@ -831,7 +839,7 @@ class Process implements \IteratorAggregate
*/ */
public function isStarted() public function isStarted()
{ {
return $this->status != self::STATUS_READY; return self::STATUS_READY != $this->status;
} }
/** /**
@ -843,7 +851,7 @@ class Process implements \IteratorAggregate
{ {
$this->updateStatus(false); $this->updateStatus(false);
return $this->status == self::STATUS_TERMINATED; return self::STATUS_TERMINATED == $this->status;
} }
/** /**
@ -1322,7 +1330,7 @@ class Process implements \IteratorAggregate
*/ */
public function checkTimeout() public function checkTimeout()
{ {
if ($this->status !== self::STATUS_STARTED) { if (self::STATUS_STARTED !== $this->status) {
return; return;
} }
@ -1513,7 +1521,7 @@ class Process implements \IteratorAggregate
$callback = $this->callback; $callback = $this->callback;
foreach ($result as $type => $data) { foreach ($result as $type => $data) {
if (3 !== $type) { 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'])) { } elseif (!isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) $data; $this->fallbackStatus['exitcode'] = (int) $data;
} }

View File

@ -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() public function testThatProcessDoesNotThrowWarningDuringRun()
{ {
if ('\\' === DIRECTORY_SEPARATOR) { if ('\\' === DIRECTORY_SEPARATOR) {
@ -313,7 +353,7 @@ class ProcessTest extends TestCase
$called = false; $called = false;
$p->run(function ($type, $buffer) use (&$called) { $p->run(function ($type, $buffer) use (&$called) {
$called = $buffer === 'foo'; $called = 'foo' === $buffer;
}); });
$this->assertTrue($called, 'The callback should be executed with the output'); $this->assertTrue($called, 'The callback should be executed with the output');
@ -326,7 +366,7 @@ class ProcessTest extends TestCase
$called = false; $called = false;
$p->run(function ($type, $buffer) use (&$called) { $p->run(function ($type, $buffer) use (&$called) {
$called = $buffer === 'foo'; $called = 'foo' === $buffer;
}); });
$this->assertTrue($called, 'The callback should be executed with the output'); $this->assertTrue($called, 'The callback should be executed with the output');