diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index 02194a14bf..0b769c520d 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -96,7 +96,7 @@ class Cookie throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires); } - $cookie .= '; expires='.substr($dateTime->format(self::$dateFormats[0]), 0, -5); + $cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0])); } if ('' !== $this->domain) { diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index bc9a193c7d..73b8e901ce 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -1048,11 +1048,16 @@ class Response */ public function getVary() { - if (!$vary = $this->headers->get('Vary')) { + if (!$vary = $this->headers->get('Vary', null, false)) { return array(); } - return is_array($vary) ? $vary : preg_split('/[\s,]+/', $vary); + $ret = array(); + foreach ($vary as $item) { + $ret = array_merge($ret, preg_split('/[\s,]+/', $item)); + } + + return $ret; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index de5112ece3..c7284ea429 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -341,6 +341,16 @@ class ResponseTest extends ResponseTestCase $response = new Response(); $response->headers->set('Vary', 'Accept-Language,User-Agent, X-Foo'); $this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by commas'); + + $vary = array('Accept-Language', 'User-Agent', 'X-foo'); + + $response = new Response(); + $response->headers->set('Vary', $vary); + $this->assertEquals($vary, $response->getVary(), '->getVary() parses multiple header name values in arrays'); + + $response = new Response(); + $response->headers->set('Vary', 'Accept-Language, User-Agent, X-foo'); + $this->assertEquals($vary, $response->getVary(), '->getVary() parses multiple header name values in arrays'); } public function testSetVary() @@ -353,7 +363,7 @@ class ResponseTest extends ResponseTestCase $this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() replace the vary header by default'); $response->setVary('X-Foo', false); - $this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() doesn\'t change the Vary header if replace is set to false'); + $this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false'); } public function testDefaultContentType() diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index 4473605e84..be08e305a2 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -304,7 +304,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter } } - $cookie .= '; expires='.substr(\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'), 0, -5); + $cookie .= '; expires='.str_replace('+0000', '', \DateTime::createFromFormat('U', $expires, new \DateTimeZone('GMT'))->format('D, d-M-Y H:i:s T')); } if ($domain) { diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 6f01e4c149..6d8802b2de 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -253,8 +253,6 @@ class Process $this->processPipes->unblock(); if ($this->tty) { - $this->status = self::STATUS_TERMINATED; - return; } @@ -481,7 +479,7 @@ class Process public function getExitCode() { if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) { - throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method'); + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'); } $this->updateStatus(false); @@ -533,7 +531,7 @@ class Process public function hasBeenSignaled() { if ($this->isSigchildEnabled()) { - throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); } $this->updateStatus(false); @@ -555,7 +553,7 @@ class Process public function getTermSignal() { if ($this->isSigchildEnabled()) { - throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved'); + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); } $this->updateStatus(false); diff --git a/src/Symfony/Component/Process/ProcessUtils.php b/src/Symfony/Component/Process/ProcessUtils.php index cde393e8bd..d5f5d9cb08 100644 --- a/src/Symfony/Component/Process/ProcessUtils.php +++ b/src/Symfony/Component/Process/ProcessUtils.php @@ -52,6 +52,9 @@ class ProcessUtils } elseif ('%' === $part) { $escapedArgument .= '^%'; } else { + if ('\\' === substr($part, -1)) { + $part .= '\\'; + } $escapedArgument .= escapeshellarg($part); } } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 4e486327b8..6bd6eaa032 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -167,7 +167,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetErrorOutput() { - $p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); + $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); $p->run(); $this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches)); @@ -175,7 +175,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetIncrementalErrorOutput() { - $p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { usleep(50000); file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); + $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { usleep(50000); file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); $p->start(); while ($p->isRunning()) { @@ -195,7 +195,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetOutput() { - $p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++; usleep(500); }'))); + $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++; usleep(500); }'))); $p->run(); $this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches)); @@ -203,7 +203,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetIncrementalOutput() { - $p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) { echo \' foo \'; usleep(50000); $n++; }'))); + $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) { echo \' foo \'; usleep(50000); $n++; }'))); $p->start(); while ($p->isRunning()) { @@ -242,11 +242,26 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process = $this->getProcess('echo "foo" >> /dev/null'); $process->setTTY(true); - $process->run(); + $process->start(); + $this->assertTrue($process->isRunning()); + $process->wait(); $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus()); } + public function testTTYCommandExitCode() + { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $this->markTestSkipped('Windows does have /dev/tty support'); + } + + $process = $this->getProcess('echo "foo" >> /dev/null'); + $process->setTTY(true); + $process->run(); + + $this->assertTrue($process->isSuccessful()); + } + public function testExitCodeText() { $process = $this->getProcess(''); @@ -260,11 +275,12 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testStartIsNonBlocking() { - $process = $this->getProcess('php -r "sleep(4);"'); + $process = $this->getProcess('php -r "usleep(500000);"'); $start = microtime(true); $process->start(); $end = microtime(true); - $this->assertLessThan(1 , $end-$start); + $this->assertLessThan(0.2, $end-$start); + $process->wait(); } public function testUpdateStatus() @@ -299,7 +315,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { $process = $this->getProcess('php -m'); $process->run(); - $this->assertEquals(0, $process->getExitCode()); + $this->assertSame(0, $process->getExitCode()); } public function testStatus() @@ -351,10 +367,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testIsNotSuccessful() { - $process = $this->getProcess('php -r "sleep(4);"'); + $process = $this->getProcess('php -r "usleep(500000);throw new \Exception(\'BOUM\');"'); $process->start(); $this->assertTrue($process->isRunning()); - $process->stop(); + $process->wait(); $this->assertFalse($process->isSuccessful()); } @@ -472,7 +488,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testRunProcessWithTimeout() { $timeout = 0.5; - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess('php -r "usleep(600000);"'); $process->setTimeout($timeout); $start = microtime(true); try { @@ -552,7 +568,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testStartAfterATimeout() { - $process = $this->getProcess('php -r "while (true) {echo \'\'; usleep(1000); }"'); + $process = $this->getProcess('php -r "$n = 1000; while ($n--) {echo \'\'; usleep(1000); }"'); $process->setTimeout(0.1); try { $process->run(); @@ -567,10 +583,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetPid() { - $process = $this->getProcess('php -r "sleep(1);"'); + $process = $this->getProcess('php -r "usleep(500000);"'); $process->start(); $this->assertGreaterThan(0, $process->getPid()); - $process->stop(); + $process->wait(); } public function testGetPidIsNullBeforeStart() diff --git a/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php b/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php index 603fac53e7..b9e8b0c76a 100644 --- a/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php @@ -31,6 +31,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase array('^%"path"^%', '%path%'), array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'), array('""', ''), + array('"with\trailingbs\\\\"', 'with\trailingbs\\'), ); } @@ -39,6 +40,7 @@ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase array("'%path%'", '%path%'), array("'<|>\" \"'\\''f'", '<|>" "\'f'), array("''", ''), + array("'with\\trailingbs\\'", 'with\trailingbs\\'), ); } } diff --git a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index d6ae226990..8580649b29 100644 --- a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php @@ -15,6 +15,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest { /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testGetExitCode() { @@ -23,6 +24,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testGetExitCodeIsNullOnStart() { @@ -31,6 +33,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testGetExitCodeIsNullOnWhenStartingAgain() { @@ -39,6 +42,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testExitCodeCommandFailed() { @@ -47,6 +51,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessIsSignaledIfStopped() { @@ -55,6 +60,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithTermSignal() { @@ -63,6 +69,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessIsNotSignaled() { @@ -71,6 +78,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage his PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithoutTermSignal() { @@ -79,6 +87,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testCheckTimeoutOnStartedProcess() { @@ -87,6 +96,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPid() { @@ -95,6 +105,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPidIsNullBeforeStart() { @@ -103,6 +114,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPidIsNullAfterRun() { @@ -111,6 +123,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testExitCodeText() { @@ -122,6 +135,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testIsSuccessful() { @@ -130,6 +144,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testIsSuccessfulOnlyAfterTerminated() { @@ -138,6 +153,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. */ public function testIsNotSuccessful() { @@ -146,6 +162,16 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method. + */ + public function testTTYCommandExitCode() + { + parent::testTTYCommandExitCode(); + } + + /** + * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled. */ public function testSignal() { @@ -154,6 +180,7 @@ class SigchildDisabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithoutTermSignalIsNotSignaled() { diff --git a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php index 3da512a4fc..524cc66374 100644 --- a/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildEnabledProcessTest.php @@ -15,6 +15,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest { /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessIsSignaledIfStopped() { @@ -23,6 +24,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithTermSignal() { @@ -31,6 +33,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessIsNotSignaled() { @@ -39,6 +42,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithoutTermSignal() { @@ -47,6 +51,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPid() { @@ -55,6 +60,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPidIsNullBeforeStart() { @@ -63,6 +69,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved. */ public function testGetPidIsNullAfterRun() { @@ -79,6 +86,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. The process can not be signaled. */ public function testSignal() { @@ -87,6 +95,7 @@ class SigchildEnabledProcessTest extends AbstractProcessTest /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException + * @expectedExceptionMessage This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved. */ public function testProcessWithoutTermSignalIsNotSignaled() { diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index c51a257dc0..ec2c65e3d0 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -95,7 +95,7 @@ EOF; } elseif (isset($test['todo']) && $test['todo']) { // TODO } else { - $expected = eval('return '.trim($test['php']).';'); + eval('$expected = '.trim($test['php']).';'); $this->assertEquals($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index c7d3b071e6..07e6222d7e 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -62,9 +62,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase if (isset($test['todo']) && $test['todo']) { // TODO } else { - $expected = var_export(eval('return '.trim($test['php']).';'), true); + eval('$expected = '.trim($test['php']).';'); - $tests[] = array($file, $expected, $test['yaml'], $test['test']); + $tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']); } } }