[Process] Make process tests more accurate on exception messages

This commit is contained in:
Romain Neutron 2014-03-11 17:00:25 +01:00
parent 0738f8387d
commit 1b1768aced
4 changed files with 40 additions and 11 deletions

View File

@ -448,7 +448,7 @@ class Process
public function getExitCode()
{
if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method');
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
}
$this->updateStatus(false);
@ -500,7 +500,7 @@ class Process
public function hasBeenSignaled()
{
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
$this->updateStatus(false);
@ -522,7 +522,7 @@ class Process
public function getTermSignal()
{
if ($this->isSigchildEnabled()) {
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved');
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
}
$this->updateStatus(false);

View File

@ -256,11 +256,12 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testStartIsNonBlocking()
{
$process = $this->getProcess('php -r "sleep(4);"');
$process = $this->getProcess('php -r "usleep(500000);"');
$start = microtime(true);
$process->start();
$end = microtime(true);
$this->assertLessThan(1 , $end-$start);
$this->assertLessThan(0.2, $end-$start);
$process->wait();
}
public function testUpdateStatus()
@ -347,10 +348,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testIsNotSuccessful()
{
$process = $this->getProcess('php -r "sleep(4);"');
$process = $this->getProcess('php -r "usleep(500000);throw new \Exception(\'BOUM\');"');
$process->start();
$this->assertTrue($process->isRunning());
$process->stop();
$process->wait();
$this->assertFalse($process->isSuccessful());
}
@ -468,7 +469,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testRunProcessWithTimeout()
{
$timeout = 0.5;
$process = $this->getProcess('php -r "sleep(3);"');
$process = $this->getProcess('php -r "usleep(600000);"');
$process->setTimeout($timeout);
$start = microtime(true);
try {
@ -509,7 +510,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testStartAfterATimeout()
{
$process = $this->getProcess('php -r "while (true) {echo \'\'; usleep(1000); }"');
$process = $this->getProcess('php -r "$n = 1000; while ($n--) {echo \'\'; usleep(1000); }"');
$process->setTimeout(0.1);
try {
$process->run();
@ -524,10 +525,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public function testGetPid()
{
$process = $this->getProcess('php -r "sleep(1);"');
$process = $this->getProcess('php -r "usleep(500000);"');
$process->start();
$this->assertGreaterThan(0, $process->getPid());
$process->stop();
$process->wait();
}
public function testGetPidIsNullBeforeStart()

View File

@ -15,6 +15,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
{
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testGetExitCode()
{
@ -23,6 +24,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testGetExitCodeIsNullOnStart()
{
@ -31,6 +33,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testGetExitCodeIsNullOnWhenStartingAgain()
{
@ -39,6 +42,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testExitCodeCommandFailed()
{
@ -47,6 +51,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsSignaledIfStopped()
{
@ -55,6 +60,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithTermSignal()
{
@ -63,6 +69,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsNotSignaled()
{
@ -71,6 +78,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignal()
{
@ -79,6 +87,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testCheckTimeoutOnStartedProcess()
{
@ -87,6 +96,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPid()
{
@ -95,6 +105,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullBeforeStart()
{
@ -103,6 +114,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullAfterRun()
{
@ -111,6 +123,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testExitCodeText()
{
@ -122,6 +135,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testIsSuccessful()
{
@ -130,6 +144,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testIsSuccessfulOnlyAfterTerminated()
{
@ -138,6 +153,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testIsNotSuccessful()
{
@ -146,6 +162,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.
*/
public function testTTYCommandExitCode()
{
@ -154,6 +171,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled.
*/
public function testSignal()
{
@ -162,6 +180,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignalIsNotSignaled()
{

View File

@ -15,6 +15,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
{
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsSignaledIfStopped()
{
@ -23,6 +24,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithTermSignal()
{
@ -31,6 +33,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessIsNotSignaled()
{
@ -39,6 +42,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignal()
{
@ -47,6 +51,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPid()
{
@ -55,6 +60,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullBeforeStart()
{
@ -63,6 +69,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.
*/
public function testGetPidIsNullAfterRun()
{
@ -79,6 +86,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled.
*/
public function testSignal()
{
@ -87,6 +95,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.
*/
public function testProcessWithoutTermSignalIsNotSignaled()
{