Adding hasBigNumber() and is64BitSystem() helper methods

This commit is contained in:
Ben Ramsey
2013-01-04 21:58:47 -06:00
parent a7766c0e40
commit ed8ec33eb1
3 changed files with 81 additions and 9 deletions
+4 -2
View File
@@ -23,10 +23,12 @@
"php": ">=5.3.3"
},
"require-dev": {
"doctrine/dbal": ">=2.3"
"doctrine/dbal": ">=2.3",
"moontoast/math": "dev-master"
},
"suggest": {
"doctrine/dbal": "Allow the use of a UUID as doctrine field type."
"doctrine/dbal": "Allow the use of a UUID as doctrine field type.",
"moontoast/math": "Provides support for large integers on 32-bit platforms."
},
"autoload": {
"psr-0": {"Rhumsaa\\Uuid": "src/"}
+35
View File
@@ -73,6 +73,21 @@ class Uuid
*/
const RESERVED_FUTURE = 7;
/**
* 64-bit system override; if true, treat the system as 32-bit (for testing)
*
* @var bool
*/
public static $force32Bit = false;
/**
* Moontoast\Math\BigNumber override; if true, treat as if BigNumber is
* not available (for testing)
*
* @var bool
*/
public static $forceNoBigNumber = false;
/**
* System override to ignore generating node from hardware (for testing)
*
@@ -761,6 +776,26 @@ class Uuid
return $node;
}
/**
* Returns true if the system has Moontoast\Math\BigNumber
*
* @return bool
*/
protected static function hasBigNumber()
{
return (class_exists('Moontoast\Math\BigNumber') && !self::$forceNoBigNumber);
}
/**
* Returns true if the system is 64-bit, false otherwise
*
* @return bool
*/
protected static function is64BitSystem()
{
return (PHP_INT_SIZE == 8 && !self::$force32Bit);
}
/**
* Returns a version 3 or 5 UUID based on the hash (md5 or sha1) of a
* namespace identifier (which is a UUID) and a name (which is a string)
+42 -7
View File
@@ -7,13 +7,8 @@ class UuidTest extends TestCase
{
protected function setUp()
{
// Skip these tests if run on a 32-bit build of PHP
if (PHP_INT_SIZE == 4) {
$this->markTestSkipped(
'Running tests on a 32-bit build of PHP; 64-bit build required.'
);
}
Uuid::$force32Bit = false;
Uuid::$forceNoBigNumber = false;
Uuid::$ignoreSystemNode = false;
}
@@ -702,6 +697,46 @@ class UuidTest extends TestCase
$this->assertFalse($uuid1->equals(null));
$this->assertFalse($uuid1->equals(new \stdClass()));
}
/**
* @covers Rhumsaa\Uuid\Uuid::hasBigNumber
*/
public function testHasBigNumber()
{
$hasBigNumber = new \ReflectionMethod(
'Rhumsaa\Uuid\Uuid', 'hasBigNumber'
);
$hasBigNumber->setAccessible(true);
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertTrue($hasBigNumber->invoke($uuid));
Uuid::$forceNoBigNumber = true;
$this->assertFalse($hasBigNumber->invoke($uuid));
}
/**
* @covers Rhumsaa\Uuid\Uuid::is64BitSystem
*/
public function testIs64BitSystem()
{
$is64BitSystem = new \ReflectionMethod(
'Rhumsaa\Uuid\Uuid', 'is64BitSystem'
);
$is64BitSystem->setAccessible(true);
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
if (PHP_INT_SIZE == 8) {
$this->assertTrue($is64BitSystem->invoke($uuid));
} else {
$this->assertFalse($is64BitSystem->invoke($uuid));
}
Uuid::$force32Bit = true;
$this->assertFalse($is64BitSystem->invoke($uuid));
}
}
/**