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

Added deprecation to cwd not existing Fixes #18249 #23708

wants to merge 25 commits into from

Conversation

alexbowers
Copy link
Contributor

@alexbowers alexbowers commented Jul 28, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #18249
License MIT
Doc PR -

/**
* @see https://github.com/symfony/symfony/issues/18249
*/
public function testCwdParameterBugDeprecationIssue18249()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just testInvalidCwd

@alexbowers
Copy link
Contributor Author

@chalasr I have renamed the test

@@ -303,6 +303,10 @@ public function start(callable $callback = null, array $env = array())
$ptsWorkaround = fopen(__FILE__, 'r');
}

if (!file_exists($this->cwd)) {
trigger_error('The provided cwd does not exist. Command is currently ran against getcwd()', E_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there must be a @ in front of the function call and it should be an E_USER_DEPRECATED, the debug component handles them gracefully. See https://symfony.com/doc/current/components/phpunit_bridge.html#trigger-deprecation-notices

$cmd = new Process('touch testing2.txt', __DIR__.'/notfound/');
$this->assertEquals(0, $cmd->run());
} catch (\Throwable $e) {
$this->assertTrue(true); // A deprecated error was thrown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing ensures that this assertion is reached.
Once the trigger_error call fixed, what you need is to just call run() (removing the try-catch around) and add as much @expectedDeprecation [expectedMessage] annotations as you need in the phpdoc bloc (https://symfony.com/doc/current/components/phpunit_bridge.html#write-assertions-about-deprecations)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been done

UPGRADE-3.4.md Outdated
@@ -68,6 +68,9 @@ Process

* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead.

* The `Symfony\Component\Process\Process` __construct `cwd` argument will throw
a deprecation warning on `run` if the folder does not exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should replace the (silent) deprecation log by a real exception in 4.0, UPGRADE-4.0.md should mention that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I put that in the upgrade log before the exception is even implemented? Or should there be a separate PR for the exception?

Copy link
Member

@chalasr chalasr Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should target 3.4. The upgrade note should be added when deprecating the behavior, we take care of doing the change when merging it up to master (because master is 4.0, where BC layers are removed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do i change the target?

If i change it now, surely doesn't it put all of master onto 3.4 which isn't what we want.

Copy link
Contributor

@robfrawley robfrawley Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to rebase your changes on top of 3.4 using git rebase and then you can change the base branch by clicking the "Edit" button on the top right of your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you can give me the details on how to rebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, I'm going away for the weekend. If somebody else wants to apply these as a patch to 3.4 instead of master, i'm more than happy for you to go ahead and do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this has been done properly now.

@@ -303,6 +303,10 @@ public function start(callable $callback = null, array $env = array())
$ptsWorkaround = fopen(__FILE__, 'r');
}

if (!file_exists($this->cwd)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't it be is_dir()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chalasr chalasr added this to the 3.4 milestone Jul 29, 2017
@@ -47,6 +47,25 @@ protected function tearDown()
}
}

/**
* @see https://github.com/symfony/symfony/issues/18249
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we don't add such notes, we rely on the git history instead, should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -303,6 +303,10 @@ public function start(callable $callback = null, array $env = array())
$ptsWorkaround = fopen(__FILE__, 'r');
}

if (!file_exists($this->cwd)) {
@trigger_error('The provided cwd does not exist. Command is currently ran against getcwd()', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message should mention that an exception will be thrown in 4.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, and the message should tell since which version this deprecation exist (see other deprecation messages in the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

public function testInvalidCwd()
{
// Check that it works fine if the CWD exists
$cmd = new Process('touch testing1.txt', __DIR__);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fails on Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should hopefully be fixed now.

@alexbowers
Copy link
Contributor Author

alexbowers commented Jul 30, 2017 via email

@nicolas-grekas
Copy link
Member

Status: needs work

@alexbowers
Copy link
Contributor Author

@nicolas-grekas Any chance you can provide a fix for windows? I have no machine to test it on.

I will fix the other issues.

@nicolas-grekas
Copy link
Member

It looks like Windows already fails when the cwd doesn't exist:
https://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx#ERROR_DIRECTORY

So you can just throw an exception on Windows - and adjust the test accordingly.

@nicolas-grekas
Copy link
Member

ping @alexbowers

@alexbowers
Copy link
Contributor Author

Thanks, I'll try to get around to it this evening. Completely forgot about this.

@alexbowers alexbowers changed the base branch from master to 3.4 September 2, 2017 02:03
@alexbowers
Copy link
Contributor Author

I think all outstanding issues were resolved, can this be confirmed?

@@ -334,7 +337,11 @@ public function start(callable $callback = null/*, array $env = array()*/)
$ptsWorkaround = fopen(__FILE__, 'r');
}

$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the $this->options property must be used, not doing so breaks windows badly

public function testInvalidCwd()
{
// Check that it works fine if the CWD exists
$cmd = new Process('echo test > testing1.txt', __DIR__);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to pipe the output to a file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
// Check that it works fine if the CWD exists
$cmd = new Process('echo test > testing1.txt', __DIR__);
$this->assertEquals(0, $cmd->run());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be assertSame - but to me this assertion is not needed: the fact that a process runs correctly when all is fine is already tested in other cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$this->assertEquals(0, $cmd->run());

$cmd = new Process('echo test > testing2.txt', __DIR__.'/notfound/');
$this->assertEquals(0, $cmd->run());
Copy link
Member

@nicolas-grekas nicolas-grekas Sep 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails on windows, where suppress_error does not make it fallback to getcwd (but fail instead)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I handle this?

I cannot test on windows, because I do not have a device to test it with.

@alexbowers
Copy link
Contributor Author

@chalasr @fabpot @nicolas-grekas

I believe all changes have been implemented.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost good :)

UPGRADE-3.4.md Outdated
@@ -68,6 +68,9 @@ Process

* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead.

* The `Symfony\Component\Process\Process` __construct `cwd` argument will throw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] constructor's $cwd argument [...]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -318,6 +318,7 @@ public function start(callable $callback = null/*, array $env = array()*/)
} elseif (null !== $env) {
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted

@@ -334,6 +335,10 @@ public function start(callable $callback = null/*, array $env = array()*/)
$ptsWorkaround = fopen(__FILE__, 'r');
}

if (!is_dir($this->cwd)) {
@trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behaviour is deprecated since version 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick to my previous suggestion: on Windows, we should throw an exception instead of a deprecation, because on Windows, it's already broken, the getcwd fallback does not apply.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
public function testInvalidCwd()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be if ('\\' === DIRECTORY_SEPARATOR) { to test for Windows, as everywhere else in the code base.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/**
* @group legacy
* @expectedDeprecation The provided cwd does not exist. Command is currently ran against getcwd(). This behaviour is deprecated since version 3.4 and will be removed in 4.0.
* @expectedException \PHPUnit_Framework_Error_Warning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be replaced by an @expectedException+@expectedExceptionMessage as suggested above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

UPGRADE-3.4.md Outdated
@@ -69,6 +69,9 @@ Process
* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead.

* The `Symfony\Component\Process\Process` constructor's $cwd argument will throw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$cwd should also be enclosed with backticks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually reword this (please also add the same entry to the CHANGELOG.md file of the Process component):

Passing a not existing working directory to the constructor of the Symfony\Component\Process\Process class is deprecated and will not be supported anymore in Symfony 4.0.

And please also add a similar entry to the UPGRADE-4.0.md file:

Passing a not existing working directory to the constructor of the Symfony\Component\Process\Process class is not supported anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these messages verbatim?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

throw new RuntimeException('The provided cwd does not exist.');
}

@trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behaviour is deprecated since version 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Symfony follow british or american spelling across the board?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

US

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ill make that change this evening

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@alexbowers
Copy link
Contributor Author

@fabpot @nicolas-grekas @chalasr

Ready for review.

@alexbowers
Copy link
Contributor Author

@fabpot do I resolve these conflicts, or do they get resolved upstream?

$this->markTestSkipped('Unix handles this automatically.');
}

// Check that it works fine if the CWD exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not test anything. To test that it works, it must be a separate test.

If the exception happens in the first process rather than the second one, the @expectedException assertion will be fine with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled this by forcing a fail if any exception occurs in that first section.

@@ -1494,7 +1534,7 @@ public function testRawCommandLine()
(
[0] => -
[1] => a
[2] =>
[2] =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted (breaks tests)

@@ -5,6 +5,7 @@ CHANGELOG
-----

* deprecated the ProcessBuilder class
* Passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is deprecated and will not be supported anymore in Symfony 4.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 * deprecated calling `Process::start()` without setting a valid working directory beforehand (via `setWorkingDirectory()` or constructor)

UPGRADE-3.4.md Outdated
@@ -210,6 +210,8 @@ Process
* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead.

* Passing a not existing working directory to the constructor of the `Symfony\Component\Process\Process` class is deprecated and will not be supported anymore in Symfony 4.0.
Copy link
Member

@chalasr chalasr Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually Process::__construct() allows null for $cwd (and fills the property using getcwd()), allowing to call setWorkingDirectory() later. Unless we want to make it non nullable, this should talk about start(), not the constructor.
I propose:

Calling `Process::start()` without setting a valid working directory (via `setWorkingDirectory()` or constructor) beforehand is deprecated and will throw an exception in 4.0.

@nicolas-grekas
Copy link
Member

@alexbowers anytime this week to fix the remaining comments?

@alexbowers
Copy link
Contributor Author

alexbowers commented Sep 26, 2017 via email

@nicolas-grekas
Copy link
Member

@alexbowers don't forget this PR, we're almost at it and it has to be in 3.4 :)

@alexbowers
Copy link
Contributor Author

@nicolas-grekas Sent the patch again.

@nicolas-grekas
Copy link
Member

Can you just apply fabbot's patch please?

@alexbowers
Copy link
Contributor Author

Done, though that is for changes not related to anything i've done as far as I can tell.

@fabpot
Copy link
Member

fabpot commented Oct 5, 2017

Thank you @alexbowers.

fabpot added a commit that referenced this pull request Oct 5, 2017
…exbowers)

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
@fabpot fabpot closed this Oct 5, 2017
@alexbowers
Copy link
Contributor Author

🍾 Only took me 69 days to actually get around to doing this.

@alexbowers alexbowers deleted the issue/process-cwd-bug branch October 5, 2017 22:29
@fabpot
Copy link
Member

fabpot commented Oct 5, 2017

Congrats! And thank you for your work and persistence @alexbowers, this is much appreciated.

fabpot added a commit that referenced this pull request Oct 6, 2017
…(xabbuh)

This PR was merged into the 4.0-dev branch.

Discussion
----------

[Process] drop non-existent working directory support

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23708
| License       | MIT
| Doc PR        |

Commits
-------

ade7c90 drop non-existent working directory support
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants