From d52dd32badb178e6cf9a9f1f662aa83a0998d609 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 19 Mar 2014 14:30:05 +0100 Subject: [PATCH] [Process] Remove unreachable code + avoid skipping tests in sigchild environment --- src/Symfony/Component/Process/Process.php | 6 +- .../Process/Tests/SimpleProcessTest.php | 74 ++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index d6e26f4697..c9ff34ed03 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -323,10 +323,6 @@ class Process } if ($this->processInformation['signaled']) { - if ($this->isSigchildEnabled()) { - throw new RuntimeException('The process has been signaled.'); - } - throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig'])); } @@ -1188,7 +1184,7 @@ class Process if (true !== @proc_terminate($this->process, $signal)) { if ($throwException) { - throw new RuntimeException(sprintf('Error while sending signal `%d`.', $signal)); + throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal)); } return false; diff --git a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php index 6655acf4ec..69ad3d5b09 100644 --- a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php @@ -27,106 +27,123 @@ class SimpleProcessTest extends AbstractProcessTest public function testGetExitCode() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case parent::testGetExitCode(); } public function testExitCodeCommandFailed() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case parent::testExitCodeCommandFailed(); } public function testProcessIsSignaledIfStopped() { - $this->skipIfPHPSigchild(); + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); parent::testProcessIsSignaledIfStopped(); } public function testProcessWithTermSignal() { - $this->skipIfPHPSigchild(); + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); parent::testProcessWithTermSignal(); } public function testProcessIsNotSignaled() { - $this->skipIfPHPSigchild(); + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); parent::testProcessIsNotSignaled(); } public function testProcessWithoutTermSignal() { - $this->skipIfPHPSigchild(); + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); parent::testProcessWithoutTermSignal(); } public function testExitCodeText() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use exitcode that is not available in this case parent::testExitCodeText(); } public function testIsSuccessful() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case parent::testIsSuccessful(); } public function testIsNotSuccessful() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case parent::testIsNotSuccessful(); } public function testGetPid() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case parent::testGetPid(); } public function testGetPidIsNullBeforeStart() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case parent::testGetPidIsNullBeforeStart(); } public function testGetPidIsNullAfterRun() { - $this->skipIfPHPSigchild(); + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case parent::testGetPidIsNullAfterRun(); } public function testSignal() { - $this->skipIfPHPSigchild(); + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); parent::testSignal(); } - /** - * @expectedException \Symfony\Component\Process\Exception\LogicException - */ + public function testProcessWithoutTermSignalIsNotSignaled() + { + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); + parent::testProcessWithoutTermSignalIsNotSignaled(); + } + + public function testProcessThrowsExceptionWhenExternallySignaled() + { + $this->skipIfPHPSigchild(); // This test use PID that is not available in this case + parent::testProcessThrowsExceptionWhenExternallySignaled(); + } + + public function testExitCodeIsAvailableAfterSignal() + { + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); + parent::testExitCodeIsAvailableAfterSignal(); + } + public function testSignalProcessNotRunning() { - $this->skipIfPHPSigchild(); + $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Can not send signal on a non running process.'); parent::testSignalProcessNotRunning(); } - /** - * @expectedException \Symfony\Component\Process\Exception\RuntimeException - */ public function testSignalWithWrongIntSignal() { - $this->skipIfPHPSigchild(); + if ($this->enabledSigchild) { + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); + } else { + $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Error while sending signal `-4`.'); + } parent::testSignalWithWrongIntSignal(); } - /** - * @expectedException \Symfony\Component\Process\Exception\RuntimeException - */ public function testSignalWithWrongNonIntSignal() { - $this->skipIfPHPSigchild(); + if ($this->enabledSigchild) { + $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); + } else { + $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Error while sending signal `Céphalopodes`.'); + } parent::testSignalWithWrongNonIntSignal(); } @@ -144,4 +161,11 @@ class SimpleProcessTest extends AbstractProcessTest $this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed'); } } + + private function expectExceptionIfPHPSigchild($classname, $message) + { + if ($this->enabledSigchild) { + $this->setExpectedException($classname, $message); + } + } }