[Process] Clean tested process on tear down

This commit is contained in:
Nicolas Grekas 2015-12-31 11:16:56 +01:00
parent 4512e3456d
commit 80e11071cc

View File

@ -23,6 +23,7 @@ use Symfony\Component\Process\ProcessPipes;
class ProcessTest extends \PHPUnit_Framework_TestCase class ProcessTest extends \PHPUnit_Framework_TestCase
{ {
private static $phpBin; private static $phpBin;
private static $process;
private static $sigchild; private static $sigchild;
private static $notEnhancedSigchild = false; private static $notEnhancedSigchild = false;
@ -42,6 +43,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild'); self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
} }
protected function tearDown()
{
if (self::$process) {
self::$process->stop(0);
self::$process = null;
}
}
public function testThatProcessDoesNotThrowWarningDuringRun() public function testThatProcessDoesNotThrowWarningDuringRun()
{ {
@trigger_error('Test Error', E_USER_NOTICE); @trigger_error('Test Error', E_USER_NOTICE);
@ -122,9 +131,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
$h = new \ReflectionProperty($p, 'process'); $h = new \ReflectionProperty($p, 'process');
$h->setAccessible(true); $h->setAccessible(true);
$h = $h->getValue($p); $h = $h->getValue($p);
$s = proc_get_status($h); $s = @proc_get_status($h);
while ($s['running']) { while (!empty($s['running'])) {
usleep(1000); usleep(1000);
$s = proc_get_status($h); $s = proc_get_status($h);
} }
@ -1012,7 +1021,11 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
} }
} }
return $process; if (self::$process) {
self::$process->stop(0);
}
return self::$process = $process;
} }
private function skipIfNotEnhancedSigchild($expectException = true) private function skipIfNotEnhancedSigchild($expectException = true)