Skip to content

Commit

Permalink
Added deprecation to cwd not existing Fixes #18249
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbowers authored and fabpot committed Oct 5, 2017
1 parent 30e3b6d commit 261eae9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-3.4.md
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
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
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
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
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

0 comments on commit 261eae9

Please sign in to comment.