Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dbb0ba8

Browse filesBrowse files
committed
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
2 parents b6e13f8 + 237b13c commit dbb0ba8
Copy full SHA for dbb0ba8

File tree

Expand file treeCollapse file tree

16 files changed

+201
-57
lines changed
Filter options
Expand file treeCollapse file tree

16 files changed

+201
-57
lines changed

‎src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php
+24-16Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ public function updateToken($series, $tokenValue, \DateTime $lastUsed)
9292
{
9393
$sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed'
9494
.' WHERE series=:series';
95-
$paramValues = array('value' => $tokenValue,
96-
'lastUsed' => $lastUsed,
97-
'series' => $series,);
98-
$paramTypes = array('value' => \PDO::PARAM_STR,
99-
'lastUsed' => DoctrineType::DATETIME,
100-
'series' => \PDO::PARAM_STR,);
95+
$paramValues = array(
96+
'value' => $tokenValue,
97+
'lastUsed' => $lastUsed,
98+
'series' => $series,
99+
);
100+
$paramTypes = array(
101+
'value' => \PDO::PARAM_STR,
102+
'lastUsed' => DoctrineType::DATETIME,
103+
'series' => \PDO::PARAM_STR,
104+
);
101105
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
102106
if ($updated < 1) {
103107
throw new TokenNotFoundException('No token found.');
@@ -112,16 +116,20 @@ public function createNewToken(PersistentTokenInterface $token)
112116
$sql = 'INSERT INTO rememberme_token'
113117
.' (class, username, series, value, lastUsed)'
114118
.' VALUES (:class, :username, :series, :value, :lastUsed)';
115-
$paramValues = array('class' => $token->getClass(),
116-
'username' => $token->getUsername(),
117-
'series' => $token->getSeries(),
118-
'value' => $token->getTokenValue(),
119-
'lastUsed' => $token->getLastUsed(),);
120-
$paramTypes = array('class' => \PDO::PARAM_STR,
121-
'username' => \PDO::PARAM_STR,
122-
'series' => \PDO::PARAM_STR,
123-
'value' => \PDO::PARAM_STR,
124-
'lastUsed' => DoctrineType::DATETIME,);
119+
$paramValues = array(
120+
'class' => $token->getClass(),
121+
'username' => $token->getUsername(),
122+
'series' => $token->getSeries(),
123+
'value' => $token->getTokenValue(),
124+
'lastUsed' => $token->getLastUsed(),
125+
);
126+
$paramTypes = array(
127+
'class' => \PDO::PARAM_STR,
128+
'username' => \PDO::PARAM_STR,
129+
'series' => \PDO::PARAM_STR,
130+
'value' => \PDO::PARAM_STR,
131+
'lastUsed' => DoctrineType::DATETIME,
132+
);
125133
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
126134
}
127135
}
+106Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Monolog\Tests;
4+
5+
use Monolog\Handler\TestHandler;
6+
use Symfony\Bridge\Monolog\Handler\DebugHandler;
7+
use Symfony\Bridge\Monolog\Logger;
8+
9+
class LoggerTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @group legacy
13+
*/
14+
public function testEmerg()
15+
{
16+
$handler = new TestHandler();
17+
$logger = new Logger('test');
18+
$logger->pushHandler($handler);
19+
20+
$this->assertTrue($logger->emerg('test'));
21+
$this->assertTrue($handler->hasEmergency('test'));
22+
}
23+
24+
/**
25+
* @group legacy
26+
*/
27+
public function testCrit()
28+
{
29+
$handler = new TestHandler();
30+
$logger = new Logger('test');
31+
$logger->pushHandler($handler);
32+
33+
$this->assertTrue($logger->crit('test'));
34+
$this->assertTrue($handler->hasCritical('test'));
35+
}
36+
37+
/**
38+
* @group legacy
39+
*/
40+
public function testErr()
41+
{
42+
$handler = new TestHandler();
43+
$logger = new Logger('test');
44+
$logger->pushHandler($handler);
45+
46+
$this->assertTrue($logger->err('test'));
47+
$this->assertTrue($handler->hasError('test'));
48+
}
49+
50+
/**
51+
* @group legacy
52+
*/
53+
public function testWarn()
54+
{
55+
$handler = new TestHandler();
56+
$logger = new Logger('test');
57+
$logger->pushHandler($handler);
58+
59+
$this->assertTrue($logger->warn('test'));
60+
$this->assertTrue($handler->hasWarning('test'));
61+
}
62+
63+
public function testGetLogs()
64+
{
65+
$logger = new Logger('test');
66+
$logger->pushHandler(new DebugHandler());
67+
68+
$logger->addInfo('test');
69+
$this->assertCount(1, $logger->getLogs());
70+
list($record) = $logger->getLogs();
71+
72+
$this->assertEquals('test', $record['message']);
73+
$this->assertEquals(Logger::INFO, $record['priority']);
74+
}
75+
76+
public function testGetLogsWithoutDebugHandler()
77+
{
78+
$logger = new Logger('test');
79+
$logger->pushHandler(new TestHandler());
80+
$logger->addInfo('test');
81+
82+
$this->assertSame(array(), $logger->getLogs());
83+
}
84+
85+
public function testCountErrors()
86+
{
87+
$logger = new Logger('test');
88+
$logger->pushHandler(new DebugHandler());
89+
90+
$logger->addInfo('test');
91+
$logger->addError('uh-oh');
92+
93+
$this->assertEquals(1, $logger->countErrors());
94+
}
95+
96+
public function testCountErrorsWithoutDebugHandler()
97+
{
98+
$logger = new Logger('test');
99+
$logger->pushHandler(new TestHandler());
100+
101+
$logger->addInfo('test');
102+
$logger->addError('uh-oh');
103+
104+
$this->assertEquals(0, $logger->countErrors());
105+
}
106+
}

‎src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testEscaping()
3131
public function testTrans($template, $expected, array $variables = array())
3232
{
3333
if ($expected != $this->getTemplate($template)->render($variables)) {
34-
print $template."\n";
34+
echo $template."\n";
3535
$loader = new \Twig_Loader_Array(array('index' => $template));
3636
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
3737
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));

‎src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ protected function setUp()
4848
$profiler = $this->mockProfiler();
4949
$twigEnvironment = $this->mockTwigEnvironment();
5050
$templates = array(
51-
'data_collector.foo' => array('foo','FooBundle:Collector:foo'),
52-
'data_collector.bar' => array('bar','FooBundle:Collector:bar'),
53-
'data_collector.baz' => array('baz','FooBundle:Collector:baz'),
51+
'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'),
52+
'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'),
53+
'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'),
5454
);
5555

5656
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);

‎src/Symfony/Component/ClassLoader/ClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ClassLoader/ClassLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function addPrefix($prefix, $paths)
9797
$paths
9898
));
9999
} elseif (!in_array($paths, $this->prefixes[$prefix])) {
100-
$this->prefixes[$prefix][] = $paths;
100+
$this->prefixes[$prefix][] = $paths;
101101
}
102102
} else {
103103
$this->prefixes[$prefix] = array_unique((array) $paths);

‎src/Symfony/Component/Console/Tests/Input/StringInputTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/StringInputTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getTokenizeData()
6363
array('"quoted"', array('quoted'), '->tokenize() parses quoted arguments'),
6464
array("'quoted'", array('quoted'), '->tokenize() parses quoted arguments'),
6565
array("'a\rb\nc\td'", array("a\rb\nc\td"), '->tokenize() parses whitespace chars in strings'),
66-
array("'a'\r'b'\n'c'\t'd'", array('a','b','c','d'), '->tokenize() parses whitespace chars between args as spaces'),
66+
array("'a'\r'b'\n'c'\t'd'", array('a', 'b', 'c', 'd'), '->tokenize() parses whitespace chars between args as spaces'),
6767
array('\"quoted\"', array('"quoted"'), '->tokenize() parses escaped-quoted arguments'),
6868
array("\'quoted\'", array('\'quoted\''), '->tokenize() parses escaped-quoted arguments'),
6969
array('-a', array('-a'), '->tokenize() parses short options'),

‎src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Tests/Node/ElementNodeTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getSpecificityValueTestData()
2929
return array(
3030
array(new ElementNode(), 0),
3131
array(new ElementNode(null, 'element'), 1),
32-
array(new ElementNode('namespace', 'element'),1),
32+
array(new ElementNode('namespace', 'element'), 1),
3333
);
3434
}
3535
}

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function getFormatToMimeTypeMapProvider()
340340
array('json', array('application/json', 'application/x-json')),
341341
array('xml', array('text/xml', 'application/xml', 'application/x-xml')),
342342
array('rdf', array('application/rdf+xml')),
343-
array('atom',array('application/atom+xml')),
343+
array('atom', array('application/atom+xml')),
344344
);
345345
}
346346

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,16 @@ public function __construct($commandline, $cwd = null, array $env = null, $input
169169

170170
public function __destruct()
171171
{
172-
// stop() will check if we have a process running.
173-
$this->stop();
172+
if ($this->isRunning()) {
173+
$this->doSignal(15, false);
174+
usleep(10000);
175+
}
176+
if ($this->isRunning()) {
177+
usleep(100000);
178+
$this->doSignal(9, false);
179+
}
180+
181+
// Don't call ->stop() nor ->close() since we don't want to wait for the subprocess here
174182
}
175183

176184
public function __clone()
@@ -1468,7 +1476,7 @@ private function doSignal($signal, $throwException)
14681476

14691477
if ('\\' === DIRECTORY_SEPARATOR) {
14701478
exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
1471-
if ($exitCode) {
1479+
if ($exitCode && $this->isRunning()) {
14721480
if ($throwException) {
14731481
throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
14741482
}

‎src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/AbstractProcessTest.php
+35-13Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public function testSetStreamAsInput($code, $size)
194194
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
195195
}
196196

197+
/**
198+
* @expectedException \Symfony\Component\Process\Exception\LogicException
199+
* @expectedExceptionMessage Input can not be set while the process is running.
200+
*/
197201
public function testSetInputWhileRunningThrowsAnException()
198202
{
199203
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
@@ -203,9 +207,10 @@ public function testSetInputWhileRunningThrowsAnException()
203207
$process->stop();
204208
$this->fail('A LogicException should have been raised.');
205209
} catch (LogicException $e) {
206-
$this->assertEquals('Input can not be set while the process is running.', $e->getMessage());
207210
}
208211
$process->stop();
212+
213+
throw $e;
209214
}
210215

211216
/**
@@ -756,6 +761,10 @@ public function testRestart()
756761
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
757762
}
758763

764+
/**
765+
* @expectedException Symfony\Component\Process\Exception\RuntimeException
766+
* @expectedExceptionMessage The process timed-out.
767+
*/
759768
public function testRunProcessWithTimeout()
760769
{
761770
$timeout = 0.5;
@@ -769,14 +778,13 @@ public function testRunProcessWithTimeout()
769778
}
770779
$duration = microtime(true) - $start;
771780

772-
if ('\\' === DIRECTORY_SEPARATOR) {
773-
// Windows is a bit slower as it read file handles, then allow twice the precision
774-
$maxDuration = $timeout + 2 * Process::TIMEOUT_PRECISION;
775-
} else {
781+
if ('\\' !== DIRECTORY_SEPARATOR) {
782+
// On Windows, timers are too transient
776783
$maxDuration = $timeout + Process::TIMEOUT_PRECISION;
784+
$this->assertLessThan($maxDuration, $duration);
777785
}
778786

779-
$this->assertLessThan($maxDuration, $duration);
787+
throw $e;
780788
}
781789

782790
public function testCheckTimeoutOnNonStartedProcess()
@@ -792,6 +800,10 @@ public function testCheckTimeoutOnTerminatedProcess()
792800
$process->checkTimeout();
793801
}
794802

803+
/**
804+
* @expectedException Symfony\Component\Process\Exception\RuntimeException
805+
* @expectedExceptionMessage The process timed-out.
806+
*/
795807
public function testCheckTimeoutOnStartedProcess()
796808
{
797809
$timeout = 0.5;
@@ -814,6 +826,8 @@ public function testCheckTimeoutOnStartedProcess()
814826

815827
$this->assertLessThan($timeout + $precision, $duration);
816828
$this->assertFalse($process->isSuccessful());
829+
830+
throw $e;
817831
}
818832

819833
public function testIdleTimeout()
@@ -852,6 +866,10 @@ public function testIdleTimeoutNotExceededWhenOutputIsSent()
852866
}
853867
}
854868

869+
/**
870+
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
871+
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
872+
*/
855873
public function testStartAfterATimeout()
856874
{
857875
$process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }')));
@@ -865,6 +883,8 @@ public function testStartAfterATimeout()
865883
$process->start();
866884
usleep(1000);
867885
$process->stop();
886+
887+
throw $e;
868888
}
869889

870890
public function testGetPid()
@@ -894,14 +914,14 @@ public function testSignal()
894914
$this->markTestSkipped('Extension pcntl is required.');
895915
}
896916

897-
$process = $this->getProcess('exec php -f '.__DIR__.'/SignalListener.php');
917+
$process = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/SignalListener.php');
898918
$process->start();
899-
usleep(500000);
900-
$process->signal(SIGUSR1);
901919

902-
while ($process->isRunning() && false === strpos($process->getOutput(), 'Caught SIGUSR1')) {
903-
usleep(10000);
920+
while (false === strpos($process->getOutput(), 'Caught')) {
921+
usleep(1000);
904922
}
923+
$process->signal(SIGUSR1);
924+
$process->wait();
905925

906926
$this->assertEquals('Caught SIGUSR1', $process->getOutput());
907927
}
@@ -962,6 +982,8 @@ public function provideMethodsThatNeedARunningProcess()
962982

963983
/**
964984
* @dataProvider provideMethodsThatNeedATerminatedProcess
985+
* @expectedException Symfony\Component\Process\Exception\LogicException
986+
* @expectedExceptionMessage Process must be terminated before calling
965987
*/
966988
public function testMethodsThatNeedATerminatedProcess($method)
967989
{
@@ -972,10 +994,10 @@ public function testMethodsThatNeedATerminatedProcess($method)
972994
$process->stop(0);
973995
$this->fail('A LogicException must have been thrown');
974996
} catch (\Exception $e) {
975-
$this->assertInstanceOf('Symfony\Component\Process\Exception\LogicException', $e);
976-
$this->assertEquals(sprintf('Process must be terminated before calling %s.', $method), $e->getMessage());
977997
}
978998
$process->stop(0);
999+
1000+
throw $e;
9791001
}
9801002

9811003
public function provideMethodsThatNeedATerminatedProcess()

‎src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public function testExitCodeIsAvailableAfterSignal()
112112
$this->markTestSkipped('Signal is not supported in sigchild environment');
113113
}
114114

115+
/**
116+
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
117+
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
118+
*/
115119
public function testStartAfterATimeout()
116120
{
117121
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.