Skip to content
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

Merged
merged 1 commit into from Jan 4, 2019

Conversation

Firehed
Copy link
Contributor

@Firehed Firehed commented Jan 3, 2019

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.

@@ -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);
Copy link
Member

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);
}

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.

ping @Simperfit could you review and tell if it's legit to you?
Note that this should target 4.1

Copy link
Member

@chalasr chalasr left a 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

@Firehed
Copy link
Contributor Author

Firehed commented Jan 3, 2019

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.
@chalasr chalasr changed the base branch from master to 3.4 January 4, 2019 04:42
@chalasr chalasr modified the milestones: 4.1, 3.4 Jan 4, 2019
@chalasr chalasr added the Console label Jan 4, 2019
@chalasr
Copy link
Member

chalasr commented Jan 4, 2019

Rebased on 3.4. Note to mergers: patch needs to be moved to TesterTrait starting from 4.1.

@chalasr
Copy link
Member

chalasr commented Jan 4, 2019

Good catch, thanks @Firehed.

@chalasr chalasr merged commit 6b87b67 into symfony:3.4 Jan 4, 2019
chalasr pushed a commit that referenced this pull request Jan 4, 2019
…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
@chalasr
Copy link
Member

chalasr commented Jan 4, 2019

And thank you for contributing to Symfony!

This was referenced Jan 6, 2019
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.

None yet

4 participants