merged 2.0

This commit is contained in:
Fabien Potencier 2012-07-09 08:31:54 +02:00
commit 5def75101e
3 changed files with 98 additions and 14 deletions

View File

@ -220,8 +220,8 @@ class Container implements IntrospectableContainerInterface
/**
* Gets a service.
*
* If a service is both defined through a set() method and
* with a set*Service() method, the former has always precedence.
* If a service is defined both through a set() method and
* with a get{$id}Service() method, the former has always precedence.
*
* @param string $id The service identifier
* @param integer $invalidBehavior The behavior when the service does not exist

View File

@ -819,6 +819,8 @@ class StubNumberFormatter
* @param mixed $value The value to be converted
*
* @return int|float The converted value
*
* @see https://bugs.php.net/bug.php?id=59597 Bug #59597
*/
private function getInt64Value($value)
{
@ -827,11 +829,33 @@ class StubNumberFormatter
}
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Range['positive'] || $value <= self::$int32Range['negative'])) {
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// The negative PHP_INT_MAX was being converted to float
if (
$value == self::$int32Range['negative'] &&
(
(version_compare(PHP_VERSION, '5.4.0', '<') && version_compare(PHP_VERSION, '5.3.14', '>=')) ||
version_compare(PHP_VERSION, '5.4.4', '>=')
)
) {
return (int) $value;
}
return (float) $value;
}
if (PHP_INT_SIZE === 8 && ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative'])) {
$value = (-2147483648 - ($value % -2147483648)) * ($value / abs($value));
if (PHP_INT_SIZE === 8) {
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// A 32 bit integer was being generated instead of a 64 bit integer
if (
($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) &&
(
(version_compare(PHP_VERSION, '5.3.14', '<')) ||
(version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
)
) {
$value = (-2147483648 - ($value % -2147483648)) * ($value / abs($value));
}
}
return (int) $value;

View File

@ -858,10 +858,20 @@ class StubNumberFormatterTest extends LocaleTestCase
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(2147483647, $parsedValue);
// Look that the parsing of '-2,147,483,648' results in a float like the literal -2147483648
$parsedValue = $formatter->parse('-2,147,483,648', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('float', $parsedValue);
$this->assertEquals(((float) -2147483647 - 1), $parsedValue);
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// The negative PHP_INT_MAX was being converted to float
if (
(version_compare(PHP_VERSION, '5.4.0', '<') && version_compare(PHP_VERSION, '5.3.14', '>=')) ||
version_compare(PHP_VERSION, '5.4.4', '>=')
) {
$this->assertInternalType('int', $parsedValue);
} else {
$this->assertInternalType('float', $parsedValue);
}
$this->assertEquals(-2147483648, $parsedValue);
}
public function testParseTypeInt64StubWith32BitIntegerInPhp64Bit()
@ -909,11 +919,31 @@ class StubNumberFormatterTest extends LocaleTestCase
$parsedValue = $formatter->parse('2,147,483,648', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(-2147483647 - 1, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// A 32 bit integer was being generated instead of a 64 bit integer
if (
(version_compare(PHP_VERSION, '5.3.14', '<')) ||
(version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
) {
$this->assertEquals(-2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).');
} else {
$this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
}
$parsedValue = $formatter->parse('-2,147,483,649', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// A 32 bit integer was being generated instead of a 64 bit integer
if (
(version_compare(PHP_VERSION, '5.3.14', '<')) ||
(version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
) {
$this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).');
} else {
$this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
}
}
// Intl Tests
@ -932,10 +962,20 @@ class StubNumberFormatterTest extends LocaleTestCase
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(2147483647, $parsedValue);
// Look that the parsing of '-2,147,483,648' results in a float like the literal -2147483648
$parsedValue = $formatter->parse('-2,147,483,648', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('float', $parsedValue);
$this->assertEquals(((float) -2147483647 - 1), $parsedValue);
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// The negative PHP_INT_MAX was being converted to float.
if (
(version_compare(PHP_VERSION, '5.4.0', '<') && version_compare(PHP_VERSION, '5.3.14', '>=')) ||
version_compare(PHP_VERSION, '5.4.4', '>=')
) {
$this->assertInternalType('int', $parsedValue);
} else {
$this->assertInternalType('float', $parsedValue);
}
$this->assertEquals(-2147483648, $parsedValue);
}
public function testParseTypeInt64IntlWith32BitIntegerInPhp64Bit()
@ -986,11 +1026,31 @@ class StubNumberFormatterTest extends LocaleTestCase
$parsedValue = $formatter->parse('2,147,483,648', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(-2147483647 - 1, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// A 32 bit integer was being generated instead of a 64 bit integer
if (
(version_compare(PHP_VERSION, '5.3.14', '<')) ||
(version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
) {
$this->assertEquals(-2147483648, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).');
} else {
$this->assertEquals(2147483648, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
}
$parsedValue = $formatter->parse('-2,147,483,649', \NumberFormatter::TYPE_INT64);
$this->assertInternalType('integer', $parsedValue);
$this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range.');
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
// A 32 bit integer was being generated instead of a 64 bit integer
if (
(version_compare(PHP_VERSION, '5.3.14', '<')) ||
(version_compare(PHP_VERSION, '5.4.0', '>=') && version_compare(PHP_VERSION, '5.4.4', '<'))
) {
$this->assertEquals(2147483647, $parsedValue, '->parse() TYPE_INT64 does not use true 64 bit integers, using only the 32 bit range (PHP < 5.3.14 and PHP < 5.4.4).');
} else {
$this->assertEquals(-2147483649, $parsedValue, '->parse() TYPE_INT64 uses true 64 bit integers (PHP >= 5.3.14 and PHP >= 5.4.4).');
}
}
/**