diff --git a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php index 562a2952da..b2216b7ae3 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/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()); + } +} diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index dc06c73dba..f4a6dbf21f 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -31,7 +31,7 @@ class TranslationExtensionTest extends \PHPUnit_Framework_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 ccf9289cf3..c8a560f6b2 100644 --- a/src/Symfony/Component/Console/Tests/Input/StringInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/StringInputTest.php @@ -63,7 +63,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 f13f4791d9..f4ddb902b5 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/Process/Process.php b/src/Symfony/Component/Process/Process.php index ed4255f077..5cfcf8b8b5 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -169,8 +169,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() @@ -1468,7 +1476,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 fca3729be8..4fe069e692 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -194,6 +194,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedLength, strlen($p->getErrorOutput())); } + /** + * @expectedException \Symfony\Component\Process\Exception\LogicException + * @expectedExceptionMessage Input can not be set while the process is running. + */ public function testSetInputWhileRunningThrowsAnException() { $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); @@ -203,9 +207,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->stop(); $this->fail('A LogicException should have been raised.'); } catch (LogicException $e) { - $this->assertEquals('Input can not be set while the process is running.', $e->getMessage()); } $process->stop(); + + throw $e; } /** @@ -756,6 +761,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; @@ -769,14 +778,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() @@ -792,6 +800,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; @@ -814,6 +826,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertLessThan($timeout + $precision, $duration); $this->assertFalse($process->isSuccessful()); + + throw $e; } public function testIdleTimeout() @@ -852,6 +866,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } } + /** + * @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException + * @expectedExceptionMessage exceeded the timeout of 0.1 seconds. + */ public function testStartAfterATimeout() { $process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }'))); @@ -865,6 +883,8 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process->start(); usleep(1000); $process->stop(); + + throw $e; } public function testGetPid() @@ -894,14 +914,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()); } @@ -962,6 +982,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) { @@ -972,10 +994,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 2668a9b4bf..645e6cf480 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\ProcessTimedOutException + * @expectedExceptionMessage exceeded the timeout of 0.1 seconds. + */ 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; diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index 9c6c0cd3f1..b5e280fb62 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 989e40b4a7..64102d22c6 100644 --- a/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php +++ b/src/Symfony/Component/Security/Acl/Dbal/AclProvider.php @@ -573,7 +573,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; @@ -615,9 +615,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 a62de61485..72e2e6a23b 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". @@ -384,7 +384,7 @@ XML; '@Type' => 'test', ), 'föo_bär' => 'a', - 'Bar' => array(1,2,3), + 'Bar' => array(1, 2, 3), 'a' => 'b', ); $expected = array( @@ -397,7 +397,7 @@ XML; '@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/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()), );