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
Ensure final input of CommandTester works with default #29754
Conversation
@@ -162,7 +162,7 @@ private static function createStream(array $inputs) | |||
{ | |||
$stream = fopen('php://memory', 'r+', false); | |||
|
|||
fwrite($stream, implode(PHP_EOL, $inputs)); | |||
fwrite($stream, implode(PHP_EOL, $inputs).PHP_EOL); |
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.
When an empty array is passed, this writes a PHP_EOL. Legit?
Should the code be rewritten as such?
foreach ($inputs as $line) {
fwrite($stream, $line.PHP_EOL);
}
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.
ping @Simperfit could you review and tell if it's legit to you?
Note that this should target 4.1
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.
Looks good to me (code owner here). 👍 once @nicolas-grekas's comment addressed
I prefer that approach too. Changed :) |
If the final element of `CommandTester::setInputs()` is an empty string (to send the default value), the internal stream the tester uses hits EOF and triggers the `Aborted` exception. This appends an additional EOL to the stream after the `implode` to simulate one final return key, allowing the final input to use the default value when used in the tester's documented style.
Rebased on 3.4. Note to mergers: patch needs to be moved to |
Good catch, thanks @Firehed. |
…rehed) This PR was merged into the 3.4 branch. Discussion ---------- Ensure final input of CommandTester works with default | Q | A | ------------- | --- | Branch? | 4.x | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If the final element of `CommandTester::setInputs()` is an empty string (to send the default value), the internal stream the tester uses hits EOF and triggers the `Aborted` exception. This appends an additional EOL to the stream after the `implode` to simulate one final return key, allowing the final input to use the default value when used in the tester's documented style. A test has been added to cover the new behavior, which failed before this change. Commits ------- 6b87b67 Ensure final input of CommandTester works with default
And thank you for contributing to Symfony! |
If the final element of
CommandTester::setInputs()
is an empty string (to send the default value), the internal stream the tester uses hits EOF and triggers theAborted
exception. This appends an additional EOL to the stream after theimplode
to simulate one final return key, allowing the final input to use the default value when used in the tester's documented style.A test has been added to cover the new behavior, which failed before this change.