Test Coverage for PeclUuidTimeGenerator

- Uses namespaced function override to "mock" the pecl extension methods.
- Tests that method will create a uuid when extension methods exist.
This commit is contained in:
Jessica Mauerhan
2016-03-13 11:40:15 -04:00
parent cd00a9cb77
commit 3290885a9c
2 changed files with 40 additions and 0 deletions
@@ -0,0 +1,22 @@
<?php
namespace Ramsey\Uuid\Generator;
define('UUID_TYPE_TIME', 1);
final class PeclUuidHelper
{
const EXAMPLE_UUID = 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6';
}
function uuid_create($type)
{
if ($type === UUID_TYPE_TIME) {
return PeclUuidHelper::EXAMPLE_UUID;
}
}
function uuid_parse($uuid)
{
return PeclUuidHelper::EXAMPLE_UUID;
}
@@ -0,0 +1,18 @@
<?php
namespace Ramsey\Uuid\Test\Generator;
use Ramsey\Uuid\Generator\PeclUuidTimeGenerator;
use Ramsey\Uuid\Test\TestCase;
use Ramsey\Uuid\Generator\PeclUuidHelper;
require_once 'PeclUuidTestHelper.php';
class PeclUuidTimeGeneratorTest extends TestCase
{
public function testGenerateCreatesUuid()
{
$generator = new PeclUuidTimeGenerator;
$uuid = $generator->generate();
$this->assertEquals(PeclUuidHelper::EXAMPLE_UUID, $uuid);
}
}