Skip to content

Commit

Permalink
Add tests for UuidGenerator, and phpunit config. (#40)
Browse files Browse the repository at this point in the history
* Add tests for UuidGenerator, and phpunit config.

* Coding standards, documentation of coding standards, defaulting to phpunit.xml.dist
  • Loading branch information
whikloj authored and ruebot committed May 6, 2016
1 parent 0062822 commit cc865fc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- composer install

script:
- php vendor/bin/phpunit test
- php vendor/bin/phpunit
- php vendor/bin/phpcs --standard=PSR2 src test

notifications:
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ Take a look at [Creating a pull request](https://help.github.com/articles/creati

You may want to read [Syncing a fork](https://help.github.com/articles/syncing-a-fork) for instructions on how to keep your fork up to date with the latest changes of the upstream (official) `Islandora-CLAW` repository.

Please note that TravisCI will test for [PSR-2](http://www.php-fig.org/psr/psr-2/) compliance. You can verify coding standard compliance with [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer), or use a utility like PHP [Coding Standards Fixer](http://cs.sensiolabs.org/).
Please note that TravisCI will test for [PSR-2](http://www.php-fig.org/psr/psr-2/) compliance. You can verify coding standard compliance with [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer).

**Note**: Due to differing interpretations of the PSR-2 coding standards do **not** use PHP [Coding Standards Fixer](http://cs.sensiolabs.org/). Coding Standards Fixer may make changes to your code that can cause it to fail our TravisCI tests.

In addition, Islandora 7.x-2.x Committers will review contributions for [PSR-4 ](http://www.php-fig.org/psr/psr-4/) compliance.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.1.0",
"easyrdf/easyrdf": "^0.9.1",
"ml/json-ld": "^1.0.4"
"ml/json-ld": "^1.0.4",
"ramsey/uuid": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
12 changes: 12 additions & 0 deletions phpunit.xml.dist
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>
43 changes: 43 additions & 0 deletions test/UuidGenerator/UuidTest.php
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");
}
}
2 changes: 2 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
include __DIR__ . '/../vendor/autoload.php'; // composer autoload

0 comments on commit cc865fc

Please sign in to comment.