mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
Adding hasBigNumber() and is64BitSystem() helper methods
This commit is contained in:
+4
-2
@@ -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/"}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user