Remove code for PHP <5.5.9

This commit is contained in:
Nicolas Grekas 2015-08-01 09:16:55 +02:00
parent dda085e8c4
commit 879771170e
19 changed files with 21 additions and 119 deletions

View File

@ -40,7 +40,7 @@ class DeprecationErrorHandler
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
}
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true);
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
$i = count($trace);
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) {

View File

@ -196,7 +196,7 @@ EOF
}
});
$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT);
return min($errors, 1);
}

View File

@ -152,7 +152,7 @@ EOF
}
});
$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT);
return min($errors, 1);
}

View File

@ -171,12 +171,7 @@ class JsonDescriptor extends Descriptor
private function writeData(array $data, array $options)
{
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
if (defined('JSON_PRETTY_PRINT')) {
$flags |= JSON_PRETTY_PRINT;
}
$this->write(json_encode($data, $flags)."\n");
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
}
/**

View File

@ -280,12 +280,10 @@ class ClassCollectionLoader
$traits = array();
if (function_exists('get_declared_traits')) {
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
$traits[] = $trait;
}
foreach ($classes as $c) {
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
if ($trait !== $c) {
$traits[] = $trait;
}
}
}

View File

@ -281,7 +281,7 @@ class Command
throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
}
if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
if ($code instanceof \Closure) {
$r = new \ReflectionFunction($code);
if (null === $r->getClosureThis()) {
$code = \Closure::bind($code, $this);

View File

@ -295,10 +295,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase
/** @dataProvider getSetCodeBindToClosureTests */
public function testSetCodeBindToClosure($previouslyBound, $expected)
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4+ only.');
}
$code = createClosure();
if ($previouslyBound) {
$code = $code->bindTo($this);

View File

@ -698,9 +698,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
{
$class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
$clone = $class->getMethod('__clone');
if (PHP_VERSION_ID >= 540000) {
$this->assertFalse($class->isCloneable());
}
$this->assertFalse($class->isCloneable());
$this->assertTrue($clone->isPrivate());
}
}

View File

@ -118,10 +118,6 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

View File

@ -143,10 +143,6 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
public function testTransformDateTimeImmutableTimezones()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

View File

@ -84,10 +84,6 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
*/
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));

View File

@ -97,10 +97,6 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');
$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');

View File

@ -58,10 +58,6 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

View File

@ -102,39 +102,12 @@ class JsonResponse extends Response
$data = json_encode($data, $this->encodingOptions);
} else {
try {
if (PHP_VERSION_ID < 50400) {
// PHP 5.3 triggers annoying warnings for some
// types that can't be serialized as JSON (INF, resources, etc.)
// but doesn't provide the JsonSerializable interface.
set_error_handler('var_dump', 0);
$data = @json_encode($data, $this->encodingOptions);
} else {
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
// objects in a new exception that needs to be removed.
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
if (PHP_VERSION_ID < 50500) {
// Clear json_last_error()
json_encode(null);
$errorHandler = set_error_handler('var_dump');
restore_error_handler();
set_error_handler(function () use ($errorHandler) {
if (JSON_ERROR_NONE === json_last_error()) {
return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args());
}
});
}
$data = json_encode($data, $this->encodingOptions);
}
if (PHP_VERSION_ID < 50500) {
restore_error_handler();
}
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
// objects in a new exception that needs to be removed.
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
$data = json_encode($data, $this->encodingOptions);
} catch (\Exception $e) {
if (PHP_VERSION_ID < 50500) {
restore_error_handler();
}
if (PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
throw $e->getPrevious() ?: $e;
}
throw $e;

View File

@ -1247,6 +1247,7 @@ class Response
{
$status = ob_get_status(true);
$level = count($status);
// PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3
$flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1;
while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) {

View File

@ -247,7 +247,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
private function doDump($data, $name, $file, $line)
{
if (PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) {
if ($this->dumper instanceof CliDumper) {
$contextDumper = function ($name, $file, $line, $fileLinkFormat) {
if ($this instanceof HtmlDumper) {
if ('' !== $file) {

View File

@ -71,11 +71,7 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase
$collector->collect(new Request(), new Response());
$output = ob_get_clean();
if (PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output);
}
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
$this->assertSame(1, $collector->getDumpsCount());
$collector->serialize();
}
@ -89,23 +85,12 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase
$collector->dump($data);
$line = __LINE__ - 1;
$file = __FILE__;
if (PHP_VERSION_ID >= 50400) {
$xOutput = <<<EOTXT
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<span class=sf-dump-num>123</span>
</pre>
EOTXT;
} else {
$len = strlen("DumpDataCollectorTest.php on line {$line}:");
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" ">"<span class=sf-dump-str title="{$len} characters">DumpDataCollectorTest.php on line {$line}:</span>"
</pre>
<pre class=sf-dump id=sf-dump data-indent-pad=" "><span class=sf-dump-num>123</span>
</pre>
EOTXT;
}
ob_start();
$response = new Response();
@ -129,10 +114,6 @@ EOTXT;
ob_start();
$collector = null;
if (PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
}
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
}
}

View File

@ -47,10 +47,7 @@ class SessionAuthenticationStrategy implements SessionAuthenticationStrategyInte
return;
case self::MIGRATE:
// Destroying the old session is broken in php 5.4.0 - 5.4.10
// See php bug #63379
$destroy = PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411;
$request->getSession()->migrate($destroy);
$request->getSession()->migrate(true);
return;

View File

@ -39,10 +39,6 @@ class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase
public function testSessionIsMigrated()
{
if (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50411) {
$this->markTestSkipped('We cannot destroy the old session on PHP 5.4.0 - 5.4.10.');
}
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));
@ -50,19 +46,6 @@ class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase
$strategy->onAuthentication($this->getRequest($session), $this->getToken());
}
public function testSessionIsMigratedWithPhp54Workaround()
{
if (PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 50411) {
$this->markTestSkipped('This PHP version is not affected.');
}
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
$session->expects($this->once())->method('migrate')->with($this->equalTo(false));
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
$strategy->onAuthentication($this->getRequest($session), $this->getToken());
}
public function testSessionIsInvalidated()
{
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');