-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Conversation
alexbowers
commented
Jul 28, 2017
•
edited
Loading
edited
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just testInvalidCwd
@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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -47,6 +47,25 @@ protected function tearDown() | |||
} | |||
} | |||
|
|||
/** | |||
* @see https://github.com/symfony/symfony/issues/18249 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fails on Windows
There was a problem hiding this comment.
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.
I'll fix the other issues either his evening or tomorrow, but I don't have access to a windows machine to test or find a working test. Thanks
… On 30 Jul 2017, at 16:33, Nicolas Grekas ***@***.***> wrote:
@nicolas-grekas commented on this pull request.
In src/Symfony/Component/Process/Tests/ProcessTest.php:
> @@ -47,6 +47,25 @@ protected function tearDown()
}
}
+ /**
+ * @see #18249
+ *
+ * @group legacy
+ * @expectedDeprecation The provided cwd does not exist. Command is currently ran against getcwd()
+ */
+ public function testInvalidCwd()
+ {
+ // Check that it works fine if the CWD exists
+ $cmd = new Process('touch testing1.txt', __DIR__);
fails on Windows
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Status: needs work |
@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. |
It looks like Windows already fails when the cwd doesn't exist: So you can just throw an exception on Windows - and adjust the test accordingly. |
ping @alexbowers |
Thanks, I'll try to get around to it this evening. Completely forgot about this. |
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); |
There was a problem hiding this comment.
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__); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
@chalasr @fabpot @nicolas-grekas I believe all changes have been implemented. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] constructor's $cwd
argument [...]
There was a problem hiding this comment.
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); | |||
} | |||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these messages verbatim?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
behavior
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
US
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@fabpot @nicolas-grekas @chalasr Ready for review. |
@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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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] => |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
@alexbowers anytime this week to fix the remaining comments? |
Yes, I'll put it in my todo list.
…On 26 September 2017 at 12:57, Nicolas Grekas ***@***.***> wrote:
@alexbowers <https://github.com/alexbowers> anytime this week to fix the
remaining comments?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23708 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAzc3qPIk28oSPfYbjQnhmGXqIDNGgozks5smOa5gaJpZM4OnFmq>
.
|
@alexbowers don't forget this PR, we're almost at it and it has to be in 3.4 :) |
@nicolas-grekas Sent the patch again. |
Can you just apply fabbot's patch please? |
Done, though that is for changes not related to anything i've done as far as I can tell. |
Thank you @alexbowers. |
…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
🍾 Only took me 69 days to actually get around to doing this. |
Congrats! And thank you for your work and persistence @alexbowers, this is much appreciated. |
…(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