From d3f671e8f60b47d71cc915b21b2c42fc5007bfbf Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Tue, 1 Dec 2015 23:08:33 +0100 Subject: [PATCH 1/3] CS: general fixes --- .../RememberMe/DoctrineTokenProvider.php | 40 +++++++++++-------- .../Extension/TranslationExtensionTest.php | 2 +- .../Tests/Profiler/TemplateManagerTest.php | 6 +-- .../Component/ClassLoader/ClassLoader.php | 2 +- .../Console/Tests/Input/StringInputTest.php | 2 +- .../Tests/Node/ElementNodeTest.php | 2 +- .../HttpFoundation/Tests/RequestTest.php | 2 +- .../Dumper/PhpGeneratorDumperTest.php | 2 +- .../Security/Acl/Dbal/AclProvider.php | 6 +-- .../Core/User/InMemoryUserProvider.php | 2 +- .../Tests/Encoder/XmlEncoderTest.php | 6 +-- .../Normalizer/GetSetMethodNormalizerTest.php | 6 +-- .../Tests/PluralizationRulesTest.php | 8 ++-- 13 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php index d078fea14e..a07e9d180a 100644 --- a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php @@ -92,12 +92,16 @@ class DoctrineTokenProvider implements TokenProviderInterface { $sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed' .' WHERE series=:series'; - $paramValues = array('value' => $tokenValue, - 'lastUsed' => $lastUsed, - 'series' => $series,); - $paramTypes = array('value' => \PDO::PARAM_STR, - 'lastUsed' => DoctrineType::DATETIME, - 'series' => \PDO::PARAM_STR,); + $paramValues = array( + 'value' => $tokenValue, + 'lastUsed' => $lastUsed, + 'series' => $series, + ); + $paramTypes = array( + 'value' => \PDO::PARAM_STR, + 'lastUsed' => DoctrineType::DATETIME, + 'series' => \PDO::PARAM_STR, + ); $updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes); if ($updated < 1) { throw new TokenNotFoundException('No token found.'); @@ -112,16 +116,20 @@ class DoctrineTokenProvider implements TokenProviderInterface $sql = 'INSERT INTO rememberme_token' .' (class, username, series, value, lastUsed)' .' VALUES (:class, :username, :series, :value, :lastUsed)'; - $paramValues = array('class' => $token->getClass(), - 'username' => $token->getUsername(), - 'series' => $token->getSeries(), - 'value' => $token->getTokenValue(), - 'lastUsed' => $token->getLastUsed(),); - $paramTypes = array('class' => \PDO::PARAM_STR, - 'username' => \PDO::PARAM_STR, - 'series' => \PDO::PARAM_STR, - 'value' => \PDO::PARAM_STR, - 'lastUsed' => DoctrineType::DATETIME,); + $paramValues = array( + 'class' => $token->getClass(), + 'username' => $token->getUsername(), + 'series' => $token->getSeries(), + 'value' => $token->getTokenValue(), + 'lastUsed' => $token->getLastUsed(), + ); + $paramTypes = array( + 'class' => \PDO::PARAM_STR, + 'username' => \PDO::PARAM_STR, + 'series' => \PDO::PARAM_STR, + 'value' => \PDO::PARAM_STR, + 'lastUsed' => DoctrineType::DATETIME, + ); $this->conn->executeUpdate($sql, $paramValues, $paramTypes); } } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index 979301d466..004cb8f57d 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -32,7 +32,7 @@ class TranslationExtensionTest extends TestCase public function testTrans($template, $expected, array $variables = array()) { if ($expected != $this->getTemplate($template)->render($variables)) { - print $template."\n"; + echo $template."\n"; $loader = new \Twig_Loader_Array(array('index' => $template)); $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false)); $twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector()))); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php index 5c8a3becb8..29238a21c4 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php @@ -48,9 +48,9 @@ class TemplateManagerTest extends TestCase $profiler = $this->mockProfiler(); $twigEnvironment = $this->mockTwigEnvironment(); $templates = array( - 'data_collector.foo' => array('foo','FooBundle:Collector:foo'), - 'data_collector.bar' => array('bar','FooBundle:Collector:bar'), - 'data_collector.baz' => array('baz','FooBundle:Collector:baz'), + 'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'), + 'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'), + 'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'), ); $this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates); diff --git a/src/Symfony/Component/ClassLoader/ClassLoader.php b/src/Symfony/Component/ClassLoader/ClassLoader.php index fc0a569485..a506dc0941 100644 --- a/src/Symfony/Component/ClassLoader/ClassLoader.php +++ b/src/Symfony/Component/ClassLoader/ClassLoader.php @@ -97,7 +97,7 @@ class ClassLoader $paths )); } elseif (!in_array($paths, $this->prefixes[$prefix])) { - $this->prefixes[$prefix][] = $paths; + $this->prefixes[$prefix][] = $paths; } } else { $this->prefixes[$prefix] = array_unique((array) $paths); diff --git a/src/Symfony/Component/Console/Tests/Input/StringInputTest.php b/src/Symfony/Component/Console/Tests/Input/StringInputTest.php index 640d226dd5..504f70a18d 100644 --- a/src/Symfony/Component/Console/Tests/Input/StringInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/StringInputTest.php @@ -54,7 +54,7 @@ class StringInputTest extends \PHPUnit_Framework_TestCase array('"quoted"', array('quoted'), '->tokenize() parses quoted arguments'), array("'quoted'", array('quoted'), '->tokenize() parses quoted arguments'), array("'a\rb\nc\td'", array("a\rb\nc\td"), '->tokenize() parses whitespace chars in strings'), - array("'a'\r'b'\n'c'\t'd'", array('a','b','c','d'), '->tokenize() parses whitespace chars between args as spaces'), + array("'a'\r'b'\n'c'\t'd'", array('a', 'b', 'c', 'd'), '->tokenize() parses whitespace chars between args as spaces'), array('\"quoted\"', array('"quoted"'), '->tokenize() parses escaped-quoted arguments'), array("\'quoted\'", array('\'quoted\''), '->tokenize() parses escaped-quoted arguments'), array('-a', array('-a'), '->tokenize() parses short options'), diff --git a/src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php b/src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php index 1db6a591a2..6d24789320 100644 --- a/src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php +++ b/src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php @@ -29,7 +29,7 @@ class ElementNodeTest extends AbstractNodeTest return array( array(new ElementNode(), 0), array(new ElementNode(null, 'element'), 1), - array(new ElementNode('namespace', 'element'),1), + array(new ElementNode('namespace', 'element'), 1), ); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index dcc1c2eb99..810fb56447 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -340,7 +340,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase array('json', array('application/json', 'application/x-json')), array('xml', array('text/xml', 'application/xml', 'application/x-xml')), array('rdf', array('application/rdf+xml')), - array('atom',array('application/atom+xml')), + array('atom', array('application/atom+xml')), ); } diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index 393aa066f5..e55a6ccf88 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php @@ -86,7 +86,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase public function testDumpWithTooManyRoutes() { $this->routeCollection->add('Test', new Route('/testing/{foo}')); - for ( $i = 0; $i < 32769; ++$i ) { + for ($i = 0; $i < 32769; ++$i) { $this->routeCollection->add('route_'.$i, new Route('/route_'.$i)); } $this->routeCollection->add('Test2', new Route('/testing2')); diff --git a/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php b/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php index 1fade3b4b2..0ccc19f4a5 100644 --- a/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php +++ b/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php @@ -571,7 +571,7 @@ QUERY; $oidCache[$oidLookupKey] = new ObjectIdentity($objectIdentifier, $classType); } - $acl = new Acl((int) $aclId, $oidCache[$oidLookupKey], $permissionGrantingStrategy, $emptyArray, !!$entriesInheriting); + $acl = new Acl((int) $aclId, $oidCache[$oidLookupKey], $permissionGrantingStrategy, $emptyArray, (bool) $entriesInheriting); // keep a local, and global reference to this ACL $loadedAcls[$classType][$objectIdentifier] = $acl; @@ -613,9 +613,9 @@ QUERY; } if (null === $fieldName) { - $loadedAces[$aceId] = new Entry((int) $aceId, $acl, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess); + $loadedAces[$aceId] = new Entry((int) $aceId, $acl, $sids[$key], $grantingStrategy, (int) $mask, (bool) $granting, (bool) $auditFailure, (bool) $auditSuccess); } else { - $loadedAces[$aceId] = new FieldEntry((int) $aceId, $acl, $fieldName, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess); + $loadedAces[$aceId] = new FieldEntry((int) $aceId, $acl, $fieldName, $sids[$key], $grantingStrategy, (int) $mask, (bool) $granting, (bool) $auditFailure, (bool) $auditSuccess); } } $ace = $loadedAces[$aceId]; diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php index 9aa39cad48..c1981deb96 100644 --- a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php @@ -97,7 +97,7 @@ class InMemoryUserProvider implements UserProviderInterface /** * Returns the user by given username. * - * @param string $username The username. + * @param string $username The username. * * @return User * diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index a6c7c9398d..bb3e7fb564 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -74,7 +74,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase '@Type' => 'test', ), 'föo_bär' => 'a', - 'Bar' => array(1,2,3), + 'Bar' => array(1, 2, 3), 'a' => 'b', ); $expected = ''."\n". @@ -283,7 +283,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase '@Type' => 'test', ), 'föo_bär' => 'a', - 'Bar' => array(1,2,3), + 'Bar' => array(1, 2, 3), 'a' => 'b', ); $expected = array( @@ -296,7 +296,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase '@Type' => 'test', ), 'föo_bär' => 'a', - 'Bar' => array(1,2,3), + 'Bar' => array(1, 2, 3), 'a' => 'b', ); $xml = $this->encoder->encode($obj, 'xml'); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index 934b81b2e7..1c5d699b5d 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -91,9 +91,9 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase public function attributeProvider() { return array( - array('attribute_test', array('attribute_test'),'AttributeTest'), - array('attribute_test', array('any'),'attribute_test'), - array('attribute', array('attribute'),'Attribute'), + array('attribute_test', array('attribute_test'), 'AttributeTest'), + array('attribute_test', array('any'), 'attribute_test'), + array('attribute', array('attribute'), 'Attribute'), array('attribute', array(), 'attribute'), ); } diff --git a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php index 43c31672c2..5de544e0c1 100644 --- a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php +++ b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php @@ -60,10 +60,10 @@ class PluralizationRulesTest extends \PHPUnit_Framework_TestCase public function successLangcodes() { return array( - array('1', array('ay','bo', 'cgg','dz','id', 'ja', 'jbo', 'ka','kk','km','ko','ky')), + array('1', array('ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky')), array('2', array('nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM')), - array('3', array('be','bs','cs','hr')), - array('4', array('cy','mt', 'sl')), + array('3', array('be', 'bs', 'cs', 'hr')), + array('4', array('cy', 'mt', 'sl')), array('5', array()), array('6', array('ar')), ); @@ -83,7 +83,7 @@ class PluralizationRulesTest extends \PHPUnit_Framework_TestCase array('1', array('fa')), array('2', array('jbo')), array('3', array('cbs')), - array('4', array('gd','kw')), + array('4', array('gd', 'kw')), array('5', array('ga')), array('6', array()), ); From 78c0a6e3a4c4277a2a1b6352468573bdda2ebb6e Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 5 Dec 2015 11:22:27 +0100 Subject: [PATCH 2/3] Added a test case for the Logger class. --- .../Bridge/Monolog/Tests/LoggerTest.php | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/Symfony/Bridge/Monolog/Tests/LoggerTest.php diff --git a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php new file mode 100644 index 0000000000..3d3c74cb73 --- /dev/null +++ b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php @@ -0,0 +1,106 @@ +pushHandler($handler); + + $this->assertTrue($logger->emerg('test')); + $this->assertTrue($handler->hasEmergency('test')); + } + + /** + * @group legacy + */ + public function testCrit() + { + $handler = new TestHandler(); + $logger = new Logger('test'); + $logger->pushHandler($handler); + + $this->assertTrue($logger->crit('test')); + $this->assertTrue($handler->hasCritical('test')); + } + + /** + * @group legacy + */ + public function testErr() + { + $handler = new TestHandler(); + $logger = new Logger('test'); + $logger->pushHandler($handler); + + $this->assertTrue($logger->err('test')); + $this->assertTrue($handler->hasError('test')); + } + + /** + * @group legacy + */ + public function testWarn() + { + $handler = new TestHandler(); + $logger = new Logger('test'); + $logger->pushHandler($handler); + + $this->assertTrue($logger->warn('test')); + $this->assertTrue($handler->hasWarning('test')); + } + + public function testGetLogs() + { + $logger = new Logger('test'); + $logger->pushHandler(new DebugHandler()); + + $logger->addInfo('test'); + $this->assertCount(1, $logger->getLogs()); + list($record) = $logger->getLogs(); + + $this->assertEquals('test', $record['message']); + $this->assertEquals(Logger::INFO, $record['priority']); + } + + public function testGetLogsWithoutDebugHandler() + { + $logger = new Logger('test'); + $logger->pushHandler(new TestHandler()); + $logger->addInfo('test'); + + $this->assertSame(array(), $logger->getLogs()); + } + + public function testCountErrors() + { + $logger = new Logger('test'); + $logger->pushHandler(new DebugHandler()); + + $logger->addInfo('test'); + $logger->addError('uh-oh'); + + $this->assertEquals(1, $logger->countErrors()); + } + + public function testCountErrorsWithoutDebugHandler() + { + $logger = new Logger('test'); + $logger->pushHandler(new TestHandler()); + + $logger->addInfo('test'); + $logger->addError('uh-oh'); + + $this->assertEquals(0, $logger->countErrors()); + } +} From 80fb51c3afdda6a6fb4e813a2216b1b3633627a2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 2 Dec 2015 17:43:18 +0100 Subject: [PATCH 3/3] [Process] Fix stopping a process on Windows --- src/Symfony/Component/Process/Process.php | 14 ++++-- .../Process/Tests/AbstractProcessTest.php | 48 ++++++++++++++----- .../Tests/SigchildEnabledProcessTest.php | 4 ++ .../Process/Tests/SignalListener.php | 12 ++--- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 676cddc67e..0f6e6f9591 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -157,8 +157,16 @@ class Process public function __destruct() { - // stop() will check if we have a process running. - $this->stop(); + if ($this->isRunning()) { + $this->doSignal(15, false); + usleep(10000); + } + if ($this->isRunning()) { + usleep(100000); + $this->doSignal(9, false); + } + + // Don't call ->stop() nor ->close() since we don't want to wait for the subprocess here } public function __clone() @@ -1190,7 +1198,7 @@ class Process if ('\\' === DIRECTORY_SEPARATOR) { exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode); - if ($exitCode) { + if ($exitCode && $this->isRunning()) { if ($throwException) { throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output))); } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 1874290936..2777411da5 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -167,6 +167,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedLength, strlen($p->getErrorOutput())); } + /** + * @expectedException Symfony\Component\Process\Exception\LogicException + * @expectedExceptionMessage STDIN can not be set while the process is running. + */ public function testSetStdinWhileRunningThrowsAnException() { $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); @@ -176,9 +180,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->stop(); $this->fail('A LogicException should have been raised.'); } catch (LogicException $e) { - $this->assertEquals('STDIN can not be set while the process is running.', $e->getMessage()); } $process->stop(); + + throw $e; } /** @@ -659,6 +664,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertNotEquals($process1->getOutput(), $process2->getOutput()); } + /** + * @expectedException Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage The process timed-out. + */ public function testRunProcessWithTimeout() { $timeout = 0.5; @@ -672,14 +681,13 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } $duration = microtime(true) - $start; - if ('\\' === DIRECTORY_SEPARATOR) { - // Windows is a bit slower as it read file handles, then allow twice the precision - $maxDuration = $timeout + 2 * Process::TIMEOUT_PRECISION; - } else { + if ('\\' !== DIRECTORY_SEPARATOR) { + // On Windows, timers are too transient $maxDuration = $timeout + Process::TIMEOUT_PRECISION; + $this->assertLessThan($maxDuration, $duration); } - $this->assertLessThan($maxDuration, $duration); + throw $e; } public function testCheckTimeoutOnNonStartedProcess() @@ -695,6 +703,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->checkTimeout(); } + /** + * @expectedException Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage The process timed-out. + */ public function testCheckTimeoutOnStartedProcess() { $timeout = 0.5; @@ -717,8 +729,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertLessThan($timeout + $precision, $duration); $this->assertFalse($process->isSuccessful()); + + throw $e; } + /** + * @expectedException Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage The process timed-out. + */ public function testStartAfterATimeout() { $process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }'))); @@ -731,6 +749,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->start(); usleep(10000); $process->stop(); + + throw $e; } public function testGetPid() @@ -760,14 +780,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Extension pcntl is required.'); } - $process = $this->getProcess('exec php -f '.__DIR__.'/SignalListener.php'); + $process = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/SignalListener.php'); $process->start(); - usleep(500000); - $process->signal(SIGUSR1); - while ($process->isRunning() && false === strpos($process->getOutput(), 'Caught SIGUSR1')) { - usleep(10000); + while (false === strpos($process->getOutput(), 'Caught')) { + usleep(1000); } + $process->signal(SIGUSR1); + $process->wait(); $this->assertEquals('Caught SIGUSR1', $process->getOutput()); } @@ -828,6 +848,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase /** * @dataProvider provideMethodsThatNeedATerminatedProcess + * @expectedException Symfony\Component\Process\Exception\LogicException + * @expectedExceptionMessage Process must be terminated before calling */ public function testMethodsThatNeedATerminatedProcess($method) { @@ -838,10 +860,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->stop(0); $this->fail('A LogicException must have been thrown'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Process\Exception\LogicException', $e); - $this->assertEquals(sprintf('Process must be terminated before calling %s.', $method), $e->getMessage()); } $process->stop(0); + + throw $e; } public function provideMethodsThatNeedATerminatedProcess() diff --git a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php index 55a50dfbd7..300560e9b5 100644 --- a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php @@ -112,6 +112,10 @@ class SigchildEnabledProcessTest extends AbstractProcessTest $this->markTestSkipped('Signal is not supported in sigchild environment'); } + /** + * @expectedException Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage The process timed-out. + */ public function testStartAfterATimeout() { if ('\\' === DIRECTORY_SEPARATOR) { diff --git a/src/Symfony/Component/Process/Tests/SignalListener.php b/src/Symfony/Component/Process/Tests/SignalListener.php index 4206550f5b..03536577c4 100644 --- a/src/Symfony/Component/Process/Tests/SignalListener.php +++ b/src/Symfony/Component/Process/Tests/SignalListener.php @@ -9,17 +9,13 @@ * file that was distributed with this source code. */ -// required for signal handling -declare (ticks = 1); +pcntl_signal(SIGUSR1, function () {echo 'SIGUSR1'; exit;}); -pcntl_signal(SIGUSR1, function () {echo 'Caught SIGUSR1'; exit;}); +echo 'Caught '; $n = 0; -// ticks require activity to work - sleep(4); does not work -while ($n < 400) { +while ($n++ < 400) { usleep(10000); - ++$n; + pcntl_signal_dispatch(); } - -return;