Skip to content

Added deprecation to cwd not existing Fixes #18249 #23708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Process/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
16 changes: 12 additions & 4 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -831,7 +839,7 @@ public function isRunning()
*/
public function isStarted()
{
return $this->status != self::STATUS_READY;
return self::STATUS_READY != $this->status;
}

/**
Expand All @@ -843,7 +851,7 @@ public function isTerminated()
{
$this->updateStatus(false);

return $this->status == self::STATUS_TERMINATED;
return self::STATUS_TERMINATED == $this->status;
}

/**
Expand Down Expand Up @@ -1322,7 +1330,7 @@ public function areEnvironmentVariablesInherited()
*/
public function checkTimeout()
{
if ($this->status !== self::STATUS_STARTED) {
if (self::STATUS_STARTED !== $this->status) {
return;
}

Expand Down Expand Up @@ -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;
}
Expand Down
44 changes: 42 additions & 2 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down