From 51c70f85dd82fe4ee553cf5e99a11b8bfe8e31b8 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Mar 2014 17:14:59 +0100 Subject: [PATCH] [Process] Fix process status in TTY mode When running a process with TTY mode, status in automatically set to `terminated` once it's started. It's wrong for two reasons : - The status of the process is not yet terminated. - The exitcode value is never caught --- src/Symfony/Component/Process/Process.php | 2 -- .../Process/Tests/AbstractProcessTest.php | 17 ++++++++++++++++- .../Tests/SigchildDisabledProcessTest.php | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 04c21c0bc4..b0d60f92f7 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -248,8 +248,6 @@ class Process $this->processPipes->unblock(); if ($this->tty) { - $this->status = self::STATUS_TERMINATED; - return; } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index c377e084b0..63684d0789 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -223,11 +223,26 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process = $this->getProcess('echo "foo" >> /dev/null'); $process->setTTY(true); - $process->run(); + $process->start(); + $this->assertTrue($process->isRunning()); + $process->wait(); $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus()); } + public function testTTYCommandExitCode() + { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $this->markTestSkipped('Windows does have /dev/tty support'); + } + + $process = $this->getProcess('echo "foo" >> /dev/null'); + $process->setTTY(true); + $process->run(); + + $this->assertTrue($process->isSuccessful()); + } + public function testExitCodeText() { $process = $this->getProcess(''); diff --git a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index d6ae226990..476a6c5471 100644 --- a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php @@ -144,6 +144,14 @@ class SigchildDisabledProcessTest extends AbstractProcessTest parent::testIsNotSuccessful(); } + /** + * @expectedException \Symfony\Component\Process\Exception\RuntimeException + */ + public function testTTYCommandExitCode() + { + parent::testTTYCommandExitCode(); + } + /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException */