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

[Console] default to stderr in the console helpers #15794

Closed
wants to merge 2 commits into from
Closed

[Console] default to stderr in the console helpers #15794

wants to merge 2 commits into from

Conversation

alcohol
Copy link
Contributor

@alcohol alcohol commented Sep 14, 2015

Interactive input/output and informational output such as progress should go to stderr if available.

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

See #13730 also for previous discussion.

If someone explicitly wants to use stdout, they can simply pass $output->getStream() instead of $output in most use-cases.

@@ -454,6 +467,10 @@ private function validateAttempts($interviewer, OutputInterface $output, $valida
{
$e = null;
while (false === $attempts || $attempts--) {
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be outside the loop

@Tobion
Copy link
Contributor

Tobion commented Sep 14, 2015

Could you create another PR against 2.7 that changes ProgressBar and QuestionHelper accordingly please?

@alcohol
Copy link
Contributor Author

alcohol commented Sep 14, 2015

Yes already working on a PR for 2.7.

Are ProgressBar and QuestionHelper the only ones eligible?
There is also a SymfonyQuestionHelper. I take it that is for internal stuff only then?

@Tobion
Copy link
Contributor

Tobion commented Sep 14, 2015

SymfonyQuestionHelper extends QuestionHelper and thus should be convered already

@alcohol
Copy link
Contributor Author

alcohol commented Sep 14, 2015

Please let me know if #15795 covers it or if any amendments need to be made.

@alcohol
Copy link
Contributor Author

alcohol commented Sep 14, 2015

@Seldaek here you go (again).

@Tobion
Copy link
Contributor

Tobion commented Sep 14, 2015

👍

Status: Reviewed

@stof
Copy link
Member

stof commented Sep 15, 2015

Tests covering this are missing

@alcohol
Copy link
Contributor Author

alcohol commented Sep 15, 2015

What would be an acceptable test scenario in your opinion, to validate these changes?

@stof
Copy link
Member

stof commented Sep 15, 2015

@alcohol Creating the helper with a ConsoleOutputInterface, and asserting that it writes its output to the error output.

@alcohol
Copy link
Contributor Author

alcohol commented Sep 15, 2015

Allright. Will implement something later today. Thanks for the feedback.

@Tobion
Copy link
Contributor

Tobion commented Sep 20, 2015

Status: Needs Work
Tests

@alcohol
Copy link
Contributor Author

alcohol commented Sep 21, 2015

@Tobion got any tips?

I tried the following for the DialogHelper for example, but yeah obviously it doesn't work as expected.

    public function testAskOnStderrWithConsoleOutput()
    {
        if (!$this->hasSttyAvailable()) {
            $this->markTestSkipped('`stderr` is required to test stderr output functionality');
        }

        $dialog = new DialogHelper();

        $dialog->setInputStream($this->getInputStream("\nnot stdout\n"));

        $this->assertEquals('stderr', $dialog->ask(new ConsoleOutput(), 'Where should output go?', 'stderr'));
        $this->assertEquals('not stdout', $dialog->ask($output = new ConsoleOutput(), 'Where should output go?', 'stderr'));

        rewind($output->getErrorOutput()->getStream());
        $this->assertEquals('Where should output go?', stream_get_contents($output->getErrorOutput()->getStream()));
    }
/srv/git/github/symfony (2.3-default-to-stderr*) $ ./phpunit src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php
PHPUnit 4.8.9 by Sebastian Bergmann and contributors.

..F....

Time: 236 ms, Memory: 6.00Mb

There was 1 failure:

1) Symfony\Component\Console\Tests\Helper\DialogHelperTest::testAskOnStderrWithConsoleOutput
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Where should output go?'
+''

/srv/git/github/symfony/src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php:81

FAILURES!
Tests: 7, Assertions: 35, Failures: 1.
Where should output go?Where should output go?KO src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php

I noticed all the tests use php://memory for output. Nothing actually ever tests stdout or stderr.

@alcohol
Copy link
Contributor Author

alcohol commented Sep 21, 2015

@Tobion, @stof, can you let me know if the above added tests are in line with what you in mind? I'll add more in that case.

fabpot added a commit that referenced this pull request Sep 22, 2015
… (alcohol)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Default to stderr for the console helpers (2.7+)

Interactive input/output and informational output such as progress should go to `stderr` if available.

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

Only merge if #15794 is merged.

If someone explicitly wants to use `stdout`, they can simply pass `$output->getStream()` instead of `$output` in most use-cases.

Commits
-------

90c2a96 Default to stderr for console helpers (only merge if #15794 gets merged)
nicolas-grekas added a commit that referenced this pull request Sep 22, 2015
* 2.7:
  [Config] Fix enum default value in Yaml dumper
  Finnish translation fix
  [CssSelector] Optimize regexs matching simple selectors
  Fix the phpdoc in the CssSelector TranslatorInterface
  [Console] Add clock mock to fix transient test on HHVM
  [DomCrawler] Optimize the regex used to find namespace prefixes
  [EventDispatcher] skip one lazy loading call
  [EventDispatcher] fix memory leak in a getListeners
  Default to stderr for console helpers (only merge if #15794 gets merged)
nicolas-grekas added a commit that referenced this pull request Sep 22, 2015
* 2.8:
  Added the right revision date for status code registry
  [Config] Fix enum default value in Yaml dumper
  fixed typo.
  [Translation][File dumper] allow get file content without writing in file.
  Finnish translation fix
  [CssSelector] Optimize regexs matching simple selectors
  Fix the phpdoc in the CssSelector TranslatorInterface
  [Console] Add clock mock to fix transient test on HHVM
  [DomCrawler] Optimize the regex used to find namespace prefixes
  [VarDumper] Add EnumStub for dumping virtual collections with casters
  [Finder] Deprecate adapters and related classes
  [EventDispatcher] skip one lazy loading call
  [EventDispatcher] fix memory leak in a getListeners
  [WebProfilerBundle] added btn-link.
  Remove duplication of the handling of regex filters in the Finder
  Default to stderr for console helpers (only merge if #15794 gets merged)

Conflicts:
	src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php
	src/Symfony/Component/EventDispatcher/EventDispatcher.php
	src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
	src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
@keradus
Copy link
Member

keradus commented Feb 6, 2016

Hi everyone !
Whan is the state of this PR ?

@alcohol
Copy link
Contributor Author

alcohol commented Feb 7, 2016

@keradus not sure, getting dusty? :d

@fabpot
Copy link
Member

fabpot commented Mar 4, 2016

Thank you @alcohol.

fabpot added a commit that referenced this pull request Mar 4, 2016
This PR was squashed before being merged into the 2.3 branch (closes #15794).

Discussion
----------

[Console] default to stderr in the console helpers

Interactive input/output and informational output such as progress should go to `stderr` if available.

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

See #13730 also for previous discussion.

If someone explicitly wants to use `stdout`, they can simply pass `$output->getStream()` instead of `$output` in most use-cases.

Commits
-------

3d4e95e [Console] default to stderr in the console helpers
@fabpot fabpot closed this Mar 4, 2016
@fabpot fabpot mentioned this pull request Mar 13, 2016
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.8:
  Added the right revision date for status code registry
  [Config] Fix enum default value in Yaml dumper
  fixed typo.
  [Translation][File dumper] allow get file content without writing in file.
  Finnish translation fix
  [CssSelector] Optimize regexs matching simple selectors
  Fix the phpdoc in the CssSelector TranslatorInterface
  [Console] Add clock mock to fix transient test on HHVM
  [DomCrawler] Optimize the regex used to find namespace prefixes
  [VarDumper] Add EnumStub for dumping virtual collections with casters
  [Finder] Deprecate adapters and related classes
  [EventDispatcher] skip one lazy loading call
  [EventDispatcher] fix memory leak in a getListeners
  [WebProfilerBundle] added btn-link.
  Remove duplication of the handling of regex filters in the Finder
  Default to stderr for console helpers (only merge if symfony#15794 gets merged)

Conflicts:
	src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php
	src/Symfony/Component/EventDispatcher/EventDispatcher.php
	src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
	src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
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.

7 participants