Skip to content

Commit

Permalink
Merge pull request #177 from davispeixoto/173-expose-versions-alterna…
Browse files Browse the repository at this point in the history
…tive1

issue #173 expose versions alternative1
  • Loading branch information
ramsey committed Aug 4, 2017
2 parents c479cdd + 46071e6 commit c141cdc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ class Uuid implements UuidInterface
*/
const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$';

/**
* Version 1 (time-based) UUID object constant identifier
*/
const UUID_TYPE_TIME = 1;

/**
* Version 2 (identifier-based) UUID object constant identifier
*/
const UUID_TYPE_IDENTIFIER = 2;

/**
* Version 3 (name-based and hashed with MD5) UUID object constant identifier
*/
const UUID_TYPE_HASH_MD5 = 3;

/**
* Version 4 (random) UUID object constant identifier
*/
const UUID_TYPE_RANDOM = 4;

/**
* Version 5 (name-based and hashed with SHA1) UUID object constant identifier
*/
const UUID_TYPE_HASH_SHA1 = 5;

/**
* The factory to use when creating UUIDs.
* @var UuidFactoryInterface
Expand Down
45 changes: 45 additions & 0 deletions tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1968,4 +1968,49 @@ public function testUuid5WithZeroName()

$this->assertEquals('b6c54489-38a0-5f50-a60a-fd8d76219cae', $uuid->toString());
}

/**
* @depends testGetVersionForVersion1
*/
public function testUuidVersionConstantForVersion1()
{
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_TIME);
}

/**
* @depends testGetVersionForVersion2
*/
public function testUuidVersionConstantForVersion2()
{
$uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e');
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_IDENTIFIER);
}

/**
* @depends testGetVersionForVersion3
*/
public function testUuidVersionConstantForVersion3()
{
$uuid = Uuid::fromString('6fa459ea-ee8a-3ca4-894e-db77e160355e');
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_HASH_MD5);
}

/**
* @depends testGetVersionForVersion4
*/
public function testUuidVersionConstantForVersion4()
{
$uuid = Uuid::fromString('6fabf0bc-603a-42f2-925b-d9f779bd0032');
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_RANDOM);
}

/**
* @depends testGetVersionForVersion5
*/
public function testUuidVersionConstantForVersion5()
{
$uuid = Uuid::fromString('886313e1-3b8a-5372-9b90-0c9aee199e5d');
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_HASH_SHA1);
}
}

0 comments on commit c141cdc

Please sign in to comment.