Add more unit tests for Pecl-based factory

Do not try to install UUID ext in HHVM run
This commit is contained in:
Thibaud Fabre
2014-12-17 02:39:03 +01:00
parent 2873c1ad3f
commit 34cc28cc30
4 changed files with 156 additions and 20 deletions
+37 -12
View File
@@ -2,27 +2,50 @@
namespace Rhumsaa\Uuid;
/**
* Factory relying on PECL UUID library whenever possible, otherwise defaulting
* to pure PHP factory.
* @author thibaud
*
*/
class PeclUuidFactory implements UuidFactoryInterface
{
/**
*
* @var UuidFactoryInterface
*/
private $factory;
/**
*
* @var boolean
*/
private $hasExt = false;
/**
*
* @param UuidFactoryInterface $factory
*/
public function __construct(UuidFactoryInterface $factory)
{
$this->hasExt = extension_loaded('uuid');
$this->factory = $factory;
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid1()
*/
public function uuid1($node = null, $clockSeq = null)
{
$uuid = uuid_create(UUID_TYPE_TIME);
if (! $this->hasExt || $node !== null || $clockSeq !== null) {
// If either param is not null, we cannot use PECL without breaking LSP.
return $this->factory->uuid1($node, $clockSeq);
}
return $this->fromString($uuid);
return $this->fromString(uuid_create(UUID_TYPE_TIME));
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid3()
*/
public function uuid3($ns, $name)
@@ -30,17 +53,19 @@ class PeclUuidFactory implements UuidFactoryInterface
return $this->factory->uuid3($ns, $name);
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid4()
*/
public function uuid4()
{
$uuid = uuid_create(UUID_TYPE_RANDOM);
if (! $this->hasExt) {
return $this->factory->uuid4();
}
return $this->fromString($uuid);
return $this->fromString(uuid_create(UUID_TYPE_RANDOM));
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::uuid5()
*/
public function uuid5($ns, $name)
@@ -48,7 +73,7 @@ class PeclUuidFactory implements UuidFactoryInterface
return $this->factory->uuid5($ns, $name);
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromBytes()
*/
public function fromBytes($bytes)
@@ -56,7 +81,7 @@ class PeclUuidFactory implements UuidFactoryInterface
return $this->factory->fromBytes($bytes);
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromString()
*/
public function fromString($name)
@@ -64,7 +89,7 @@ class PeclUuidFactory implements UuidFactoryInterface
return $this->factory->fromString($name);
}
/*
/**
* (non-PHPdoc) @see \Rhumsaa\Uuid\UuidFactoryInterface::fromInteger()
*/
public function fromInteger($integer)