diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar index 402e17b2f2..040e136a34 100644 Binary files a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar and b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtensionInPhar.phar differ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/createphar.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/createphar.php index cfe9425c50..5fa06a0eb5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/createphar.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/createphar.php @@ -44,4 +44,4 @@ $phar->addFromString('schema/project-1.0.xsd', << EOT ); -$phar->setStub(''); +$phar->setStub(''); diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 048ba69274..00e4d33f7a 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -241,7 +241,7 @@ class Filesystem $this->chgrp(new \FilesystemIterator($file), $group, true); } if (is_link($file) && function_exists('lchgrp')) { - if (true !== @lchgrp($file, $group)) { + if (true !== @lchgrp($file, $group) || (defined('HHVM_VERSION') && !posix_getgrnam($group))) { throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file); } } else { diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 5a1e802090..4c59666b9d 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -916,7 +916,7 @@ class Form implements \IteratorAggregate, FormInterface $child->setParent($this); if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) { - $iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child))); + $iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child->getName() => $child))); $iterator = new \RecursiveIteratorIterator($iterator); $this->config->getDataMapper()->mapDataToForms($viewData, $iterator); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index e552fc7477..ea91946fc3 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -350,7 +350,7 @@ class CompoundFormTest extends AbstractFormTest ->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator')) ->will($this->returnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child, $test) { $test->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator()); - $test->assertSame(array($child), iterator_to_array($iterator)); + $test->assertSame(array($child->getName() => $child), iterator_to_array($iterator)); })); $form->initialize(); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php index f7722c496e..200cbc3282 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php @@ -15,6 +15,6 @@ abstract class DateTimeTestCase extends \PHPUnit_Framework_TestCase { public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual) { - self::assertEquals($expected->format('c'), $actual->format('c')); + self::assertEquals($expected->format('U'), $actual->format('U')); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index e2146d8434..851e6752b0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -216,7 +216,6 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase { $storage = $this->getStorage(); - $this->assertFalse(isset($_SESSION)); $this->assertFalse($storage->getSaveHandler()->isActive()); $this->assertFalse($storage->isStarted()); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 0acc4458cc..07d560f711 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -91,7 +91,6 @@ class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase $storage = $this->getStorage(); - $this->assertFalse(isset($_SESSION)); $this->assertFalse($storage->getSaveHandler()->isActive()); $this->assertFalse($storage->isStarted()); diff --git a/src/Symfony/Component/Process/PhpExecutableFinder.php b/src/Symfony/Component/Process/PhpExecutableFinder.php index 91d6d78a67..f8f57cc536 100644 --- a/src/Symfony/Component/Process/PhpExecutableFinder.php +++ b/src/Symfony/Component/Process/PhpExecutableFinder.php @@ -37,7 +37,7 @@ class PhpExecutableFinder { // HHVM support if (defined('HHVM_VERSION')) { - return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : ''); + return (getenv('PHP_BINARY') ?: PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : ''); } // PHP_BINARY return the current sapi executable diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 7e26976d62..96fd5fd98a 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -11,21 +11,30 @@ namespace Symfony\Component\Process\Tests; -use Symfony\Component\Process\Exception\ProcessTimedOutException; use Symfony\Component\Process\Exception\LogicException; +use Symfony\Component\Process\Exception\ProcessTimedOutException; +use Symfony\Component\Process\Exception\RuntimeException; +use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Pipes\PipesInterface; use Symfony\Component\Process\Process; -use Symfony\Component\Process\Exception\RuntimeException; /** * @author Robert Schönthal */ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { + protected static $phpBin; + + public static function setUpBeforeClass() + { + $phpBin = new PhpExecutableFinder(); + self::$phpBin = $phpBin->find(); + } + public function testThatProcessDoesNotThrowWarningDuringRun() { @trigger_error('Test Error', E_USER_NOTICE); - $process = $this->getProcess("php -r 'sleep(3)'"); + $process = $this->getProcess(self::$phpBin." -r 'sleep(3)'"); $process->run(); $actualError = error_get_last(); $this->assertEquals('Test Error', $actualError['message']); @@ -95,7 +104,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $expectedOutputSize = PipesInterface::CHUNK_SIZE * 2 + 2; $code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code))); $p->start(); // Let's wait enough time for process to finish... @@ -134,7 +143,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testProcessResponses($expected, $getter, $code) { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code))); $p->run(); $this->assertSame($expected, $p->$getter()); @@ -150,7 +159,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $expected = str_repeat(str_repeat('*', 1024), $size).'!'; $expectedLength = (1024 * $size) + 1; - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code))); $p->setInput($expected); $p->run(); @@ -170,7 +179,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase fwrite($stream, $expected); rewind($stream); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code))); $p->setInput($stream); $p->run(); @@ -182,7 +191,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testSetInputWhileRunningThrowsAnException() { - $process = $this->getProcess('php -r "usleep(500000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $process->start(); try { $process->setInput('foobar'); @@ -201,7 +210,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testInvalidInput($value) { - $process = $this->getProcess('php -v'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->setInput($value); } @@ -218,7 +227,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testValidInput($expected, $value) { - $process = $this->getProcess('php -v'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->setInput($value); $this->assertSame($expected, $process->getInput()); } @@ -260,7 +269,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testCallbackIsExecutedForOutput() { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('echo \'foo\';'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('echo \'foo\';'))); $called = false; $p->run(function ($type, $buffer) use (&$called) { @@ -272,7 +281,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetErrorOutput() { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, 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)); @@ -285,7 +294,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock'); file_put_contents($lock, 'W'); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); $p->start(); while ($p->isRunning()) { @@ -301,7 +310,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testFlushErrorOutput() { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }'))); $p->run(); $p->clearErrorOutput(); @@ -315,7 +324,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock'); file_put_contents($lock, 'W'); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); $p->start(); @@ -341,7 +350,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetOutput() { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }'))); $p->run(); $this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches)); @@ -354,7 +363,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock'); file_put_contents($lock, 'W'); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); $p->start(); while ($p->isRunning()) { @@ -370,7 +379,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testFlushOutput() { - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}'))); $p->run(); $p->clearOutput(); @@ -384,7 +393,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock'); file_put_contents($lock, 'W'); - $p = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); + $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }'))); $p->start(); @@ -530,7 +539,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testStartIsNonBlocking() { - $process = $this->getProcess('php -r "usleep(500000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $start = microtime(true); $process->start(); $end = microtime(true); @@ -540,14 +549,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testUpdateStatus() { - $process = $this->getProcess('php -h'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertTrue(strlen($process->getOutput()) > 0); } public function testGetExitCodeIsNullOnStart() { - $process = $this->getProcess('php -r "usleep(200000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"'); $this->assertNull($process->getExitCode()); $process->start(); $this->assertNull($process->getExitCode()); @@ -557,7 +566,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetExitCodeIsNullOnWhenStartingAgain() { - $process = $this->getProcess('php -r "usleep(200000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"'); $process->run(); $this->assertEquals(0, $process->getExitCode()); $process->start(); @@ -568,14 +577,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetExitCode() { - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertSame(0, $process->getExitCode()); } public function testStatus() { - $process = $this->getProcess('php -r "usleep(500000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $this->assertFalse($process->isRunning()); $this->assertFalse($process->isStarted()); $this->assertFalse($process->isTerminated()); @@ -594,7 +603,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testStop() { - $process = $this->getProcess('php -r "sleep(4);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(4);"'); $process->start(); $this->assertTrue($process->isRunning()); $process->stop(); @@ -603,14 +612,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testIsSuccessful() { - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertTrue($process->isSuccessful()); } public function testIsSuccessfulOnlyAfterTerminated() { - $process = $this->getProcess('php -r "sleep(1);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(1);"'); $process->start(); while ($process->isRunning()) { $this->assertFalse($process->isSuccessful()); @@ -622,7 +631,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testIsNotSuccessful() { - $process = $this->getProcess('php -r "usleep(500000);throw new \Exception(\'BOUM\');"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);throw new \Exception(\'BOUM\');"'); $process->start(); $this->assertTrue($process->isRunning()); $process->wait(); @@ -635,7 +644,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Windows does not support POSIX signals'); } - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertFalse($process->hasBeenSignaled()); } @@ -646,7 +655,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Windows does not support POSIX signals'); } - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertFalse($process->hasBeenSignaled()); } @@ -657,7 +666,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Windows does not support POSIX signals'); } - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertEquals(0, $process->getTermSignal()); } @@ -668,7 +677,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Windows does not support POSIX signals'); } - $process = $this->getProcess('php -r "sleep(4);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(4);"'); $process->start(); $process->stop(); $this->assertTrue($process->hasBeenSignaled()); @@ -683,7 +692,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase // SIGTERM is only defined if pcntl extension is present $termSignal = defined('SIGTERM') ? SIGTERM : 15; - $process = $this->getProcess('php -r "sleep(4);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(4);"'); $process->start(); $process->stop(); @@ -712,7 +721,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testRestart() { - $process1 = $this->getProcess('php -r "echo getmypid();"'); + $process1 = $this->getProcess(self::$phpBin.' -r "echo getmypid();"'); $process1->run(); $process2 = $process1->restart(); @@ -734,7 +743,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase // Sleep doesn't work as it will allow the process to handle signals and close // file handles from the other end. - $process = $this->getProcess('php -r "while (true) {}"'); + $process = $this->getProcess(self::$phpBin.' -r "while (true) {}"'); $process->start(); // PHP will deadlock when it tries to cleanup $process @@ -743,7 +752,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testRunProcessWithTimeout() { $timeout = 0.5; - $process = $this->getProcess('php -r "usleep(600000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(600000);"'); $process->setTimeout($timeout); $start = microtime(true); try { @@ -765,13 +774,13 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testCheckTimeoutOnNonStartedProcess() { - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(3);"'); $process->checkTimeout(); } public function testCheckTimeoutOnTerminatedProcess() { - $process = $this->getProcess('php -v'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $process->checkTimeout(); } @@ -780,7 +789,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { $timeout = 0.5; $precision = 100000; - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(3);"'); $process->setTimeout($timeout); $start = microtime(true); @@ -802,7 +811,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testIdleTimeout() { - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(3);"'); $process->setTimeout(10); $process->setIdleTimeout(0.5); @@ -819,7 +828,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testIdleTimeoutNotExceededWhenOutputIsSent() { - $process = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 30; while ($n--) {echo "foo\n"; usleep(100000); }'))); + $process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 30; while ($n--) {echo "foo\n"; usleep(100000); }'))); $process->setTimeout(2); $process->setIdleTimeout(1); @@ -835,7 +844,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testStartAfterATimeout() { - $process = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }'))); + $process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }'))); $process->setTimeout(0.1); try { @@ -850,7 +859,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetPid() { - $process = $this->getProcess('php -r "usleep(500000);"'); + $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $process->start(); $this->assertGreaterThan(0, $process->getPid()); $process->wait(); @@ -858,13 +867,13 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testGetPidIsNullBeforeStart() { - $process = $this->getProcess('php -r "sleep(1);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(1);"'); $this->assertNull($process->getPid()); } public function testGetPidIsNullAfterRun() { - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->run(); $this->assertNull($process->getPid()); } @@ -909,7 +918,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testSignalProcessNotRunning() { $this->verifyPosixIsEnabled(); - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $process->signal(SIGHUP); } @@ -918,7 +927,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testMethodsThatNeedARunningProcess($method) { - $process = $this->getProcess('php -m'); + $process = $this->getProcess(self::$phpBin.' -v'); $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method)); $process->{$method}(); } @@ -939,7 +948,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testMethodsThatNeedATerminatedProcess($method) { - $process = $this->getProcess('php -r "sleep(1);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(1);"'); $process->start(); try { $process->{$method}(); @@ -981,7 +990,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('POSIX signals do not work on Windows'); } - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(3);"'); $process->start(); $process->signal(-4); } @@ -995,14 +1004,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('POSIX signals do not work on Windows'); } - $process = $this->getProcess('php -r "sleep(3);"'); + $process = $this->getProcess(self::$phpBin.' -r "sleep(3);"'); $process->start(); $process->signal('Céphalopodes'); } public function testDisableOutputDisablesTheOutput() { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $this->assertFalse($p->isOutputDisabled()); $p->disableOutput(); $this->assertTrue($p->isOutputDisabled()); @@ -1012,7 +1021,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testDisableOutputWhileRunningThrowsException() { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $p->start(); $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Disabling output while the process is running is not possible.'); $p->disableOutput(); @@ -1020,7 +1029,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testEnableOutputWhileRunningThrowsException() { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $p->disableOutput(); $p->start(); $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Enabling output while the process is running is not possible.'); @@ -1029,7 +1038,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase public function testEnableOrDisableOutputAfterRunDoesNotThrowException() { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $p->disableOutput(); $p->start(); $p->wait(); @@ -1065,7 +1074,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testStartWithACallbackAndDisabledOutput($startMethod, $exception, $exceptionMessage) { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $p->disableOutput(); $this->setExpectedException($exception, $exceptionMessage); $p->{$startMethod}(function () {}); @@ -1085,7 +1094,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase */ public function testGetOutputWhileDisabled($fetchMethod) { - $p = $this->getProcess('php -r "usleep(500000);"'); + $p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"'); $p->disableOutput(); $p->start(); $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output has been disabled.'); diff --git a/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php b/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php index 20b12b1c3c..61a471b4f6 100644 --- a/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php +++ b/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php @@ -102,7 +102,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Cannot test when open_basedir is set'); } - $this->iniSet('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/'); + $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : '')); $finder = new ExecutableFinder(); $result = $finder->find($this->getPhpBinaryName()); @@ -125,7 +125,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase } $this->setPath(''); - $this->iniSet('open_basedir', PHP_BINARY.PATH_SEPARATOR.'/'); + $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : '')); $finder = new ExecutableFinder(); $result = $finder->find($this->getPhpBinaryName(), false); diff --git a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php index 8f8623930f..cd4abedc9d 100644 --- a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php +++ b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php @@ -53,10 +53,10 @@ class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase $f = new PhpExecutableFinder(); - $current = $f->find(); + $current = getenv('PHP_BINARY') ?: PHP_BINARY; - $this->assertEquals($f->find(), $current.' --php', '::find() returns the executable PHP'); - $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP'); + $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP'); + $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP'); } /** diff --git a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php index 4bf9ad87c6..98eeb0ecbc 100644 --- a/src/Symfony/Component/Process/Tests/SimpleProcessTest.php +++ b/src/Symfony/Component/Process/Tests/SimpleProcessTest.php @@ -150,7 +150,7 @@ class SimpleProcessTest extends AbstractProcessTest public function testStopTerminatesProcessCleanly() { try { - $process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"'); + $process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"'); $process->run(function () use ($process) { $process->stop(); }); @@ -164,7 +164,7 @@ class SimpleProcessTest extends AbstractProcessTest $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); try { - $process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"'); + $process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"'); $process->run(function () use ($process) { if ($process->isRunning()) { $process->signal(defined('SIGKILL') ? SIGKILL : 9); @@ -180,7 +180,7 @@ class SimpleProcessTest extends AbstractProcessTest $this->expectExceptionIfPHPSigchild('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild. The process can not be signaled.'); try { - $process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"'); + $process = $this->getProcess(self::$phpBin.' -r "echo \'foo\'; sleep(1); echo \'bar\';"'); $process->run(function () use ($process) { if ($process->isRunning()) { $process->signal(defined('SIGTERM') ? SIGTERM : 15); diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index 170c5b4dcf..f45271a439 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php @@ -39,7 +39,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase $this->routeCollection = new RouteCollection(); $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection); - $this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.php'; + $this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php'; @unlink($this->testTmpFilepath); } diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index b46b1bc3cf..ff6db4d758 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -165,7 +165,8 @@ class SwitchUserListener implements ListenerInterface } if (null !== $this->dispatcher) { - $switchEvent = new SwitchUserEvent($request, $original->getUser()); + $user = $this->provider->refreshUser($original->getUser()); + $switchEvent = new SwitchUserEvent($request, $user); $this->dispatcher->dispatch(SecurityEvents::SWITCH_USER, $switchEvent); } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php index 9fb4e50e73..2be0325a17 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -11,7 +11,9 @@ namespace Symfony\Component\Security\Http\Tests\Firewall; +use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\Firewall\SwitchUserListener; +use Symfony\Component\Security\Http\SecurityEvents; class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase { @@ -100,6 +102,56 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase $listener->handle($this->event); } + public function testExitUserDispatchesEventWithRefreshedUser() + { + $originalUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); + $refreshedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); + $this + ->userProvider + ->expects($this->any()) + ->method('refreshUser') + ->with($originalUser) + ->willReturn($refreshedUser); + $originalToken = $this->getToken(); + $originalToken + ->expects($this->any()) + ->method('getUser') + ->willReturn($originalUser); + $role = $this + ->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole') + ->disableOriginalConstructor() + ->getMock(); + $role->expects($this->any())->method('getSource')->willReturn($originalToken); + $this + ->securityContext + ->expects($this->any()) + ->method('getToken') + ->willReturn($this->getToken(array($role))); + $this + ->request + ->expects($this->any()) + ->method('get') + ->with('_switch_user') + ->willReturn('_exit'); + $this + ->request + ->expects($this->any()) + ->method('getUri') + ->willReturn('/'); + + $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $dispatcher + ->expects($this->once()) + ->method('dispatch') + ->with(SecurityEvents::SWITCH_USER, $this->callback(function (SwitchUserEvent $event) use ($refreshedUser) { + return $event->getTargetUser() === $refreshedUser; + })) + ; + + $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher); + $listener->handle($this->event); + } + /** * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException */ diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php index ff4519686f..7815111d9d 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php @@ -137,12 +137,12 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase public function testStartTime() { $event = new StopwatchEvent(microtime(true) * 1000); - $this->assertTrue($event->getStartTime() < 0.5); + $this->assertLessThan(0.5, $event->getStartTime()); $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); $event->stop(); - $this->assertTrue($event->getStartTime() < 1); + $this->assertLessThan(1, $event->getStartTime()); $event = new StopwatchEvent(microtime(true) * 1000); $event->start(); diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 320eb50721..0776e4fa8d 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -50,15 +50,19 @@ class InlineTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Your platform does not support locales.'); } - $required_locales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'); - if (false === setlocale(LC_ALL, $required_locales)) { - $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $required_locales)); + try { + $requiredLocales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'); + if (false === setlocale(LC_NUMERIC, $requiredLocales)) { + $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $requiredLocales)); + } + + $this->assertEquals('1.2', Inline::dump(1.2)); + $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0))); + setlocale(LC_NUMERIC, $locale); + } catch (\Exception $e) { + setlocale(LC_NUMERIC, $locale); + throw $e; } - - $this->assertEquals('1.2', Inline::dump(1.2)); - $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0))); - - setlocale(LC_ALL, $locale); } public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()