minor #10492 [2.3][Process] Remove unreachable code + avoid skipping tests in sigchild environment (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Process] Remove unreachable code + avoid skipping tests in sigchild environment

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

As mentioned by @Tobion in https://github.com/symfony/symfony/pull/10480#issuecomment-38002910, I removed the dead code. I also fixed/updated the test suite on PHP compiled with `--enable-sigchild`.

Commits
-------

d52dd32 [Process] Remove unreachable code + avoid skipping tests in sigchild environment
This commit is contained in:
Fabien Potencier 2014-03-19 16:52:49 +01:00
commit c29b4214b6
2 changed files with 50 additions and 30 deletions

View File

@ -324,10 +324,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;

View File

@ -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);
}
}
}