]> granicus.if.org Git - php/commitdiff
New basic tests for uniqid(). Tested on Windows, Linux and Linux 64 bit
authorandy wharmby <wharmby@php.net>
Mon, 17 Aug 2009 14:22:02 +0000 (14:22 +0000)
committerandy wharmby <wharmby@php.net>
Mon, 17 Aug 2009 14:22:02 +0000 (14:22 +0000)
ext/standard/tests/general_functions/uniqid_basic.phpt [new file with mode: 0644]
ext/standard/tests/general_functions/uniqid_error.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/general_functions/uniqid_basic.phpt b/ext/standard/tests/general_functions/uniqid_basic.phpt
new file mode 100644 (file)
index 0000000..9a9c573
--- /dev/null
@@ -0,0 +1,73 @@
+--TEST--\r
+Test uniqid() function : basic functionality\r
+--FILE--\r
+<?php\r
+/* Prototype  : string uniqid  ([ string $prefix= ""  [, bool $more_entropy= false  ]] )\r
+ * Description: Gets a prefixed unique identifier based on the current time in microseconds. \r
+ * Source code: ext/standard/uniqid.c\r
+*/\r
+echo "*** Testing uniqid() : basic functionality ***\n";\r
+\r
+echo "\nuniqid() without a prefix\n";\r
+var_dump(uniqid());\r
+var_dump(uniqid(null, true));\r
+var_dump(uniqid(null, false));\r
+echo "\n\n";\r
+\r
+echo "uniqid() with a prefix\n";\r
+\r
+// Use a fixed prefix so we can ensure length of o/p id is fixed \r
+$prefix = array (\r
+                               99999,\r
+                               "99999",\r
+                               10.5e2,\r
+                               null,\r
+                               true,\r
+                               false                           \r
+                               );\r
+\r
+for ($i = 0; $i < count($prefix); $i++) {                              \r
+       var_dump(uniqid($prefix[$i]));\r
+       var_dump(uniqid($prefix[$i], true));\r
+       var_dump(uniqid($prefix[$i], false));\r
+       echo "\n";\r
+}      \r
+\r
+?>\r
+===DONE===\r
+--EXPECTF-- \r
+*** Testing uniqid() : basic functionality ***\r
+\r
+uniqid() without a prefix\r
+string(13) "%s"\r
+string(23) "%s.%s"\r
+string(13) "%s"\r
+\r
+\r
+uniqid() with a prefix\r
+string(18) "99999%s"\r
+string(28) "99999%s.%s"\r
+string(18) "99999%s"\r
+\r
+string(18) "999994%s"\r
+string(28) "999994%s.%s"\r
+string(18) "999994%s"\r
+\r
+string(17) "1050%s"\r
+string(27) "1050%s.%s"\r
+string(17) "1050%s"\r
+\r
+string(13) "%s"\r
+string(23) "%s.%s"\r
+string(13) "%s"\r
+\r
+string(14) "1%s"\r
+string(24) "1%s.%s"\r
+string(14) "1%s"\r
+\r
+string(13) "%s"\r
+string(23) "%s.%s"\r
+string(13) "%s"\r
+\r
+===DONE===\r
+       
\ No newline at end of file
diff --git a/ext/standard/tests/general_functions/uniqid_error.phpt b/ext/standard/tests/general_functions/uniqid_error.phpt
new file mode 100644 (file)
index 0000000..9608431
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--\r
+Test uniqid() function : error conditions\r
+--FILE--\r
+<?php\r
+/* Prototype  : string uniqid  ([ string $prefix= ""  [, bool $more_entropy= false  ]] )\r
+ * Description: Gets a prefixed unique identifier based on the current time in microseconds. \r
+ * Source code: ext/standard/uniqid.c\r
+*/\r
+echo "*** Testing uniqid() : error conditions ***\n";\r
+\r
+echo "\n-- Testing uniqid() function with more than expected no. of arguments --\n";\r
+$prefix = null;\r
+$more_entropy = false;\r
+$extra_arg = false;\r
+var_dump(uniqid($prefix, $more_entropy, $extra_arg));\r
+\r
+echo "\n-- Testing uniqid() function with invalid values for \$prefix --\n";\r
+class class1{}\r
+$obj = new class1();\r
+$res = fopen(__FILE__, "r"); \r
+$array = array(1,2,3);\r
+\r
+uniqid($array, false);\r
+uniqid($res, false);\r
+uniqid($obj, false);\r
+\r
+fclose($res);\r
+\r
+?>\r
+===DONE===\r
+--EXPECTF-- \r
+*** Testing uniqid() : error conditions ***\r
+\r
+-- Testing uniqid() function with more than expected no. of arguments --\r
+\r
+Warning: uniqid() expects at most 2 parameters, 3 given in %s on line %d\r
+NULL\r
+\r
+-- Testing uniqid() function with invalid values for $prefix --\r
+\r
+Warning: uniqid() expects parameter 1 to be string, array given in %s on line %d\r
+\r
+Warning: uniqid() expects parameter 1 to be string, resource given in %s on line %d\r
+\r
+Warning: uniqid() expects parameter 1 to be string, object given in %s on line %d\r
+===DONE===
\ No newline at end of file