Add Guid test.
authorJan Schneider <jan@horde.org>
Sun, 2 Jan 2011 22:42:51 +0000 (23:42 +0100)
committerJan Schneider <jan@horde.org>
Sun, 2 Jan 2011 22:42:51 +0000 (23:42 +0100)
framework/Support/test/Horde/Support/GuidTest.php [new file with mode: 0644]
framework/Support/test/Horde/Support/RandomidTest.php
framework/Support/test/Horde/Support/UuidTest.php

diff --git a/framework/Support/test/Horde/Support/GuidTest.php b/framework/Support/test/Horde/Support/GuidTest.php
new file mode 100644 (file)
index 0000000..b60a06f
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Support
+ * @subpackage UnitTests
+ * @copyright  2010 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+
+/**
+ * @category   Horde
+ * @package    Support
+ * @subpackage UnitTests
+ * @copyright  2010 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+class Horde_Support_GuidTest extends PHPUnit_Framework_TestCase
+{
+    public function testFormat()
+    {
+        $this->assertEquals(48, strlen(new Horde_Support_Guid()));
+        $this->assertRegExp('/\d{14}\.\w{23}@localhost/', (string)new Horde_Support_Guid());
+    }
+
+    public function testDuplicates()
+    {
+        $values = array();
+        $cnt = 0;
+
+        for ($i = 0; $i < 10000; ++$i) {
+            $id = strval(new Horde_Support_Guid());
+            if (isset($values[$id])) {
+                $cnt++;
+            } else {
+                $values[$id] = 1;
+            }
+        }
+
+        $this->assertEquals(0, $cnt);
+    }
+
+    public function testOptions()
+    {
+        $this->assertStringEndsWith('example.com', (string)new Horde_Support_Guid(array('server' => 'example.com')));
+        $this->assertRegExp('/\d{14}\.prefix\.\w{23}@localhost/', (string)new Horde_Support_Guid(array('prefix' => 'prefix')));
+    }
+}
index 7645ba1..3208444 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 /**
- * @group      support
  * @category   Horde
  * @package    Support
  * @subpackage UnitTests
  */
 class Horde_Support_RandomidTest extends PHPUnit_Framework_TestCase
 {
-    public function testRandomidDuplicates()
+    public function testLength()
+    {
+        $this->assertEquals(23, strlen(new Horde_Support_Randomid()));
+    }
+
+    public function testDuplicates()
     {
         $values = array();
         $cnt = 0;
@@ -33,5 +37,4 @@ class Horde_Support_RandomidTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals(0, $cnt);
     }
-
 }
index 5b3d7b0..721dcb5 100644 (file)
@@ -3,30 +3,25 @@
  * @category   Horde
  * @package    Support
  * @subpackage UnitTests
- * @copyright  1999-2009 The Horde Project (http://www.horde.org/)
+ * @copyright  1999-2010 The Horde Project (http://www.horde.org/)
  * @license    http://opensource.org/licenses/bsd-license.php
  */
 
 /**
- * @group      support
  * @category   Horde
  * @package    Support
  * @subpackage UnitTests
- * @copyright  1999-2009 The Horde Project (http://www.horde.org/)
+ * @copyright  1999-2010 The Horde Project (http://www.horde.org/)
  * @license    http://opensource.org/licenses/bsd-license.php
  */
 class Horde_Support_UuidTest extends PHPUnit_Framework_TestCase
 {
-    /**
-     * test instantiating a normal timer
-     */
-    public function testUuidLength()
+    public function testLength()
     {
-        $uuid = strval(new Horde_Support_Uuid());
-        $this->assertEquals(36, strlen($uuid));
+        $this->assertEquals(36, strlen(new Horde_Support_Uuid()));
     }
 
-    public function testUuidDuplicates()
+    public function testDuplicates()
     {
         $values = array();
         $cnt = 0;
@@ -42,5 +37,4 @@ class Horde_Support_UuidTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals(0, $cnt);
     }
-
 }