From 7658af1e06c4cce26f932d034798eb33bc9e0e7a Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Fri, 15 Nov 2013 08:39:44 -0500 Subject: [PATCH] Fixed exception handling and added tests to complete test coverage. --- src/Lootils/Uuid/Exception.php | 7 +++ test/UUIDTest.php | 92 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/Lootils/Uuid/Exception.php diff --git a/src/Lootils/Uuid/Exception.php b/src/Lootils/Uuid/Exception.php new file mode 100644 index 0000000..fbd1d0a --- /dev/null +++ b/src/Lootils/Uuid/Exception.php @@ -0,0 +1,7 @@ +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. */ @@ -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. */ @@ -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. */