-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for UuidGenerator, and phpunit config. (#40)
* Add tests for UuidGenerator, and phpunit config. * Coding standards, documentation of coding standards, defaulting to phpunit.xml.dist
- Loading branch information
Showing
6 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit bootstrap="./test/bootstrap.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="chullo"> | ||
<directory>test</directory> | ||
</testsuite> | ||
<testsuite name="uuid"> | ||
<directory>test/UuidGenerator</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
use Islandora\Chullo\Uuid\UuidGenerator; | ||
|
||
class UuidTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Islandora\Chullo\Uuid\UuidGenerator::generateV4 | ||
*/ | ||
public function testGenerateV4() | ||
{ | ||
# Not much we can do other than verify we got something | ||
# that looks like a UUID. | ||
$version4_regex = "/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i"; | ||
$generator = new UuidGenerator(); | ||
$uuid = $generator->generateV4(); | ||
$this->assertEquals(1, preg_match($version4_regex, $uuid), "Did not build a correct Uuid V4."); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Chullo\Uuid\UuidGenerator::generateV5 | ||
*/ | ||
public function testGenerateV5() | ||
{ | ||
$namespace = 'islandora.ca'; | ||
$object_name = 'test_object'; | ||
|
||
$namespace_uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace); | ||
$test_uuid = Uuid::uuid5($namespace_uuid->toString(), $object_name); | ||
|
||
$generator = new UuidGenerator($namespace); | ||
$uuid5 = $generator->generateV5($object_name); | ||
$this->assertEquals($test_uuid->toString(), $uuid5, "Did not build the correct UUID v5."); | ||
|
||
$generator2 = new UuidGenerator(); | ||
$uuid5_2 = $generator2->generateV5($object_name, $namespace); | ||
$this->assertEquals($test_uuid->toString(), $uuid5_2, "Did not build the correct UUID v5"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
include __DIR__ . '/../vendor/autoload.php'; // composer autoload |