From fa247495374d2ea9e3dcf3069fd6905d31e2de0a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Mar 2014 17:04:39 +0100 Subject: [PATCH 1/9] [Yaml] fix for a HHVM bug --- src/Symfony/Component/Yaml/Tests/DumperTest.php | 2 +- src/Symfony/Component/Yaml/Tests/ParserTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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']); } } } From d014dacce3f757f2d39d1f7a8ba31d7e6ee8a384 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Mar 2014 17:47:46 +0100 Subject: [PATCH 2/9] made Cookie stringification more robust --- src/Symfony/Component/BrowserKit/Cookie.php | 2 +- .../Component/HttpKernel/DataCollector/RequestDataCollector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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) { From 3a4a3cbe303cfe71f40c1d3425882e1426a6bcfc Mon Sep 17 00:00:00 2001 From: Beth Binkovitz Date: Tue, 4 Mar 2014 14:15:32 -0600 Subject: [PATCH 3/9] 10158 get vary multiple --- src/Symfony/Component/HttpFoundation/Response.php | 10 ++++++++-- .../HttpFoundation/Tests/ResponseTest.php | 14 +++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 828c868c3c..9cb68cc576 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -987,11 +987,17 @@ 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 6de11dc0d0..051975fe2c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -284,6 +284,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'); + + $response = new Response(); + $vary = array( + 'Accept-Language', + 'User-Agent', + 'X-foo', + ); + $response->headers->set('Vary', $vary); + $this->assertEquals($response->headers->get('Vary', NULL, FALSE) , $response->getVary(), '->getVary() parses multiple header name values in arrays'); + } public function testSetVary() @@ -296,7 +306,9 @@ 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->assertTrue(in_array('Accept-Language', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false'); + $this->assertTrue(in_array('User-Agent', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false'); + $this->assertTrue(in_array('X-Foo', $response->getVary()), '->setVary() adds new Vary headers when replace is set to false'); } public function testDefaultContentType() From 1017d83260c0750ab63875fcf55458c30b72b8db Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 5 Mar 2014 08:16:11 +0100 Subject: [PATCH 4/9] [HttpFoundation] added some unit tests --- .../Component/HttpFoundation/Response.php | 3 +-- .../HttpFoundation/Tests/ResponseTest.php | 20 +++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 9cb68cc576..37e6c610c2 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -991,10 +991,9 @@ class Response return array(); } - $ret = array(); foreach ($vary as $item) { - $ret = array_merge($ret, preg_split('/[\s,]+/', $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 051975fe2c..b9a2b9376f 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -285,15 +285,15 @@ class ResponseTest extends ResponseTestCase $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'); - $response = new Response(); - $vary = array( - 'Accept-Language', - 'User-Agent', - 'X-foo', - ); - $response->headers->set('Vary', $vary); - $this->assertEquals($response->headers->get('Vary', NULL, FALSE) , $response->getVary(), '->getVary() parses multiple header name values in arrays'); + $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() @@ -306,9 +306,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->assertTrue(in_array('Accept-Language', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false'); - $this->assertTrue(in_array('User-Agent', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false'); - $this->assertTrue(in_array('X-Foo', $response->getVary()), '->setVary() adds new Vary headers when 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() From d66f63f2b8f4bdfe12be5818a520d8c1eb1265eb Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Mar 2014 16:55:29 +0100 Subject: [PATCH 5/9] [Process] Use assertSame instead of assertEquals to avoid comparison against `null` --- src/Symfony/Component/Process/Tests/AbstractProcessTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index c377e084b0..809cab928a 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -280,7 +280,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() From 51c70f85dd82fe4ee553cf5e99a11b8bfe8e31b8 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Mar 2014 17:14:59 +0100 Subject: [PATCH 6/9] [Process] Fix process status in TTY mode When running a process with TTY mode, status in automatically set to `terminated` once it's started. It's wrong for two reasons : - The status of the process is not yet terminated. - The exitcode value is never caught --- src/Symfony/Component/Process/Process.php | 2 -- .../Process/Tests/AbstractProcessTest.php | 17 ++++++++++++++++- .../Tests/SigchildDisabledProcessTest.php | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 04c21c0bc4..b0d60f92f7 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -248,8 +248,6 @@ class Process $this->processPipes->unblock(); if ($this->tty) { - $this->status = self::STATUS_TERMINATED; - return; } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index c377e084b0..63684d0789 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -223,11 +223,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(''); diff --git a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index d6ae226990..476a6c5471 100644 --- a/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php @@ -144,6 +144,14 @@ class SigchildDisabledProcessTest extends AbstractProcessTest parent::testIsNotSuccessful(); } + /** + * @expectedException \Symfony\Component\Process\Exception\RuntimeException + */ + public function testTTYCommandExitCode() + { + parent::testTTYCommandExitCode(); + } + /** * @expectedException \Symfony\Component\Process\Exception\RuntimeException */ From 1b1768aced9818ddd891326d9a306f729799ac33 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 11 Mar 2014 17:00:25 +0100 Subject: [PATCH 7/9] [Process] Make process tests more accurate on exception messages --- src/Symfony/Component/Process/Process.php | 6 +++--- .../Process/Tests/AbstractProcessTest.php | 17 +++++++++-------- .../Tests/SigchildDisabledProcessTest.php | 19 +++++++++++++++++++ .../Tests/SigchildEnabledProcessTest.php | 9 +++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index b0d60f92f7..c9efa3649a 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -448,7 +448,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); @@ -500,7 +500,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); @@ -522,7 +522,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/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index c587830e4d..1baf15f3d6 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -256,11 +256,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() @@ -347,10 +348,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()); } @@ -468,7 +469,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 { @@ -509,7 +510,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(); @@ -524,10 +525,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/SigchildDisabledProcessTest.php b/src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php index 476a6c5471..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,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 testTTYCommandExitCode() { @@ -154,6 +171,7 @@ class SigchildDisabledProcessTest 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() { @@ -162,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() { From 227b85bc27ee51a3a489e13804dae07477965c30 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 11 Mar 2014 18:32:12 +0100 Subject: [PATCH 8/9] [Process] Fix some unit tests that create the process object instead of delegate it to the implementation --- .../Component/Process/Tests/AbstractProcessTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 1baf15f3d6..b5b34b2197 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -166,7 +166,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)); @@ -174,7 +174,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()) { @@ -185,7 +185,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)); @@ -193,7 +193,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()) { From 10e903aa5d8b8789dd94ab8489d5e387448457ec Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 12 Mar 2014 15:41:28 +0100 Subject: [PATCH 9/9] [Process] Fix #9160 : escaping an argument with a trailing backslash on windows fails --- src/Symfony/Component/Process/ProcessUtils.php | 3 +++ src/Symfony/Component/Process/Tests/ProcessUtilsTest.php | 2 ++ 2 files changed, 5 insertions(+) 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/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\\'), ); } }