Skip to content

Commit 5731516

Browse files
committed
merged branch lenar/dialoghelper-eof (PR #1704)
Commits ------- 07298ac Detect EOF when reading input stream Discussion ---------- [Console] Detect EOF when reading input stream This is related to commits 511a9a1 and 3a5d508. First of them introduced abort-on-EOF and the second regressed the functionality. Problem is stream_get_line() doesn't return false on EOF. So it needs call to feof() to detect the situation. Still, it's not ideal. With fgets() it worked fine, but with stream_get_line() one has to press CTRL+D twice to get out. I presume this could be bug in PHP itself. But better than nothing. Please consider. --------------------------------------------------------------------------- by fabpot at 2011/07/19 22:47:53 -0700 I have used `stream_get_line` especially because it does not return `false` on eof. This is needed when you pass your own stream for unit tests. --------------------------------------------------------------------------- by lenar at 2011/07/25 06:05:59 -0700 This is not the best solution I think. Tests should mimic and cope with real life not the other way around. Better solution would be to fix testcase. Like this: lenar/SensioGeneratorBundle@6ff3f26. Or maybe create a special "testing" stream wrapper that wraps php://memory and gives out just linefeeds after real data ends. And then change stream_get_line() back to fgets() if there is no other reason for this change. --------------------------------------------------------------------------- by fabpot at 2011/07/25 06:24:20 -0700 When applying your patch to the generator bundle (and revert to use `fgets`), I get "RuntimeException: Aborted" exceptions. --------------------------------------------------------------------------- by lenar at 2011/07/25 06:35:08 -0700 With d326f89 added + lenar/SensioGeneratorBundle@6ff3f26 I can successfully run every test in that file. --------------------------------------------------------------------------- by fabpot at 2011/07/26 23:31:36 -0700 @lenar: not for me. I have many 'Aborted' exception on my Mac. --------------------------------------------------------------------------- by fabpot at 2011/07/26 23:41:18 -0700 And I have the exact same errors on Linux: There were 7 errors: 1) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #0 (array('/tmp'), 'Foo/BarBundle ', array('Foo\\BarBundle', 'FooBarBundle', '/tmp/', 'annotation', false)) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:97 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:165 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39 2) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #1 (array('/tmp'), 'Foo/BarBundle BarBundle foo yml n', array('Foo\\BarBundle', 'BarBundle', 'foo/', 'yml', false)) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:62 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:83 .../Symfony/Component/Console/Command/Command.php:214 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39 3) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateBundleCommandTest::testInteractiveCommand with data set #2 (array('/tmp', 'yml', 'BarBundle', true), 'Foo/BarBundle ', array('Foo\\BarBundle', 'BarBundle', '/tmp/', 'yml', true)) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:97 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateBundleCommand.php:165 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateBundleCommandTest.php:39 4) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #0 (array(), 'AcmeBlogBundle:Blog/Post ', array('Blog\\Post', 'annotation', array())) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:97 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:145 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39 5) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #1 (array('AcmeBlogBundle:Blog/Post'), '', array('Blog\\Post', 'annotation', array())) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:97 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:121 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39 6) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #2 (array(), 'AcmeBlogBundle:Blog/Post yml ', array('Blog\\Post', 'yml', array())) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:62 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:153 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39 7) Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateDoctrineEntityCommandTest::testInteractiveCommand with data set #3 (array(), 'AcmeBlogBundle:Blog/Post yml title 255 description text ', array('Blog\\Post', 'yml', array(array('title', 'string', 255), array('description', 'text')))) RuntimeException: Aborted .../Symfony/Component/Console/Helper/DialogHelper.php:40 .../Symfony/Component/Console/Helper/DialogHelper.php:62 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineEntityCommand.php:153 .../Symfony/Component/Console/Command/Command.php:205 .../Symfony/Component/Console/Tester/CommandTester.php:66 .../symfony-standard/vendor/bundles/Sensio/Bundle/GeneratorBundle/Tests/Command/GenerateDoctrineEntityCommandTest.php:39 --------------------------------------------------------------------------- by lenar at 2011/07/26 23:56:46 -0700 @fabpot: and you modified all those tests? I only modified ```Tests/Command/GenerateDoctrineCrudCommandTest.php``` and that doesn't fail as I see from your log. I just provided example, though I could add necessary changes for other tests too. --------------------------------------------------------------------------- by fabpot at 2011/07/27 00:09:32 -0700 @lenar: ah, sorry about that. Then, can you provide a fix for all the other tests too? Thanks a lot. --------------------------------------------------------------------------- by lenar at 2011/07/27 00:22:54 -0700 @fabpot: actually what do you think about this kind of fix instead for tests: lenar/SensioGeneratorBundle@517f263cb01ea2ea1ef2 instead my previous proposal (lenar/SensioGeneratorBundle@6ff3f26). Really simple, short and effective. --------------------------------------------------------------------------- by fabpot at 2011/07/27 00:37:51 -0700 @lenar: looks good to me. Can you create a PR? --------------------------------------------------------------------------- by lenar at 2011/07/27 00:45:36 -0700 @fabpot: sensiolabs/SensioGeneratorBundle#60
2 parents 8700cd6 + 07298ac commit 5731516

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class DialogHelper extends Helper
2222
{
23-
private $inputStream;
23+
private $inputStream = STDIN;
2424

2525
/**
2626
* Asks a question to the user.
@@ -35,7 +35,8 @@ public function ask(OutputInterface $output, $question, $default = null)
3535
{
3636
$output->write($question);
3737

38-
if (false === $ret = stream_get_line(null === $this->inputStream ? STDIN : $this->inputStream, 4096, "\n")) {
38+
$ret = fgets($this->inputStream, 4096);
39+
if (false === $ret) {
3940
throw new \RuntimeException('Aborted');
4041
}
4142
$ret = trim($ret);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy