Skip to content

Commit

Permalink
Fixed exception handling and added tests to complete test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Nov 15, 2013
1 parent dda3771 commit 7658af1
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Lootils/Uuid/Exception.php
@@ -0,0 +1,7 @@
<?php
/**
* UUID Exception
*/
namespace Lootils\Uuid;

class Exception extends \Exception {}
92 changes: 92 additions & 0 deletions test/UUIDTest.php
Expand Up @@ -96,6 +96,14 @@ public function testV3() {
}
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID provided for the namespace is not valid.
*/
public function testInvalidNamespaceCreateV3Exception() {
$uuid = Uuid::createV3('foo', 'bar');
}

/**
* Test v5 UUID.
*/
Expand Down Expand Up @@ -133,6 +141,14 @@ public function testV5() {
}
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID provided for the namespace is not valid.
*/
public function testInvalidNamespaceCreateV5Exception() {
$uuid = Uuid::createV5('foo', 'bar');
}

/**
* Test parsing a UUID as a string when wrapped by {}.
*/
Expand All @@ -141,6 +157,14 @@ public function testParseUUID() {
$this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $uuid->getUuid());
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID string supplied could not be parsed.
*/
public function testStringToPartsException() {
$uuid = new Uuid('{35e872b4-190a-5faa-a0f6-09da0d4f9c01-453}');
}

/**
* Test setting and getting information around a UUID.
*/
Expand Down Expand Up @@ -181,6 +205,57 @@ public function testArrays() {
$this->assertEquals('35e872b4-190a-5faa-a0f6-09da0d4f9c01', $uuid2->getUuid());
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID array supplied could not be parsed.
*/
public function testParseLongArrayException() {
$uuid = new Uuid(array('35e872b4', '190a', '5faa', 'a0', 'f6', '09da0d4f9c01', 'foo'));
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID array supplied could not be parsed.
*/
public function testParseArrayStructureException() {
$array = array('foo', '35e872b4', '190a', '5faa', 'a0', 'f6', '09da0d4f9c01');
unset($array[0]);
$uuid = new Uuid($array);
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID string supplied could not be parsed.
*/
public function testParseStringException() {
$uuid = new Uuid('foo');
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID supplied could not be parsed.
*/
public function testParseUnknownType() {
$test = new StdClass();
$uuid = new Uuid($test);
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage An invalid UUID version was specified.
*/
public function testInvalidSetVersionException() {
$uuid = new Uuid(array('35e872b4', '190a', '5faa', 'a0', 'f6', '09da0d4f9c01'), 7);
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage The UUID provided for the namespace is not valid.
*/
public function testInvalidUuidBinException() {
$uuid = Uuid::bin('foo');
}

/**
* Make sure fields are properly getting into their place.
*/
Expand All @@ -201,6 +276,23 @@ public function testFields() {
}
}

/**
* @expectedException \Lootils\Uuid\Exception
* @expectedExceptionMessage A field value was requested for an invalid field name.
*/
public function testGetFieldException() {
$array = array(
'time_low' => '35e872b4',
'time_mid' => '190a',
'time_hi_version' => '5faa',
'clock_seq_hi_variant' => 'a0',
'clock_seq_low' => 'f6',
'node' => '09da0d4f9c01',
);
$uuid = new Uuid($array, Uuid::V5, Uuid::DNS, 'mattfarina.com');
$uuid->getField('foo');
}

/**
* Test __toString converting an object to a valid UUID.
*/
Expand Down

0 comments on commit 7658af1

Please sign in to comment.