Merge branch '2.7' into 2.8
* 2.7: [Process] Fix stopping a process on Windows Added a test case for the Logger class. CS: general fixes
This commit is contained in:
commit
dbb0ba8f11
@ -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);
|
||||
}
|
||||
}
|
||||
|
106
src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Normal file
106
src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\Monolog\Tests;
|
||||
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Symfony\Bridge\Monolog\Handler\DebugHandler;
|
||||
use Symfony\Bridge\Monolog\Logger;
|
||||
|
||||
class LoggerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testEmerg()
|
||||
{
|
||||
$handler = new TestHandler();
|
||||
$logger = new Logger('test');
|
||||
$logger->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());
|
||||
}
|
||||
}
|
@ -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())));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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'),
|
||||
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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'));
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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 = '<?xml version="1.0"?>'."\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');
|
||||
|
@ -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()),
|
||||
);
|
||||
|
Reference in New Issue
Block a user