diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index bfba2f5da1..e7eac45a63 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -843,8 +843,8 @@ class Application if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); - } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { - $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); + } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('question')) { + $inputStream = $this->getHelperSet()->get('question')->getInputStream(); if (!@posix_isatty($inputStream)) { $input->setInteractive(false); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index eed6c81323..eebaa0629a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -959,6 +959,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command'); } + + public function testCanCheckIfTerminalIsInteractive() + { + if (!function_exists('posix_isatty')) { + $this->markTestSkipped('posix_isatty function is required'); + } + + $application = new CustomDefaultCommandApplication(); + $application->setAutoExit(false); + + $tester = new ApplicationTester($application); + $tester->run(array('command' => 'help')); + + $this->assertTrue($tester->getInput()->isInteractive()); + $this->assertFalse($tester->getInput()->hasParameterOption(array('--no-interaction', '-n'))); + + $inputStream = $application->getHelperSet()->get('question')->getInputStream(); + $this->assertEquals($tester->getInput()->isInteractive(), @posix_isatty($inputStream)); + } } class CustomApplication extends Application