]> granicus.if.org Git - php/commitdiff
Basic tests for function_exists() and get_defined_functions(). Tested on Windows...
authorandy wharmby <wharmby@php.net>
Sun, 14 Jun 2009 13:49:19 +0000 (13:49 +0000)
committerandy wharmby <wharmby@php.net>
Sun, 14 Jun 2009 13:49:19 +0000 (13:49 +0000)
Zend/tests/function_exists_basic.phpt [new file with mode: 0644]
Zend/tests/function_exists_error.phpt [new file with mode: 0644]
Zend/tests/function_exists_variation1.phpt [new file with mode: 0644]
Zend/tests/get_defined_functions_basic.phpt [new file with mode: 0644]
Zend/tests/get_defined_functions_error.phpt [new file with mode: 0644]

diff --git a/Zend/tests/function_exists_basic.phpt b/Zend/tests/function_exists_basic.phpt
new file mode 100644 (file)
index 0000000..469e3d8
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+function_exists function : basic functionality 
+--FILE--
+<?php
+/* 
+ * proto bool function_exists(string function_name)
+ * Function is implemented in Zend/zend_builtin_functions.c
+*/ 
+
+echo "*** Testing function_exists() : basic functionality ***\n";
+
+echo "Internal function: ";
+var_dump(function_exists('function_exists'));
+
+echo "User defined function: ";
+function f() {}
+var_dump(function_exists('f'));
+
+echo "Case sensitivity: ";
+var_dump(function_exists('F'));
+
+echo "Non existent function: ";
+var_dump(function_exists('g'));
+
+echo "Method: ";
+Class C {
+       static function f() {}
+}
+var_dump(function_exists('C::f'));
+?>
+===Done===
+--EXPECT--
+*** Testing function_exists() : basic functionality ***
+Internal function: bool(true)
+User defined function: bool(true)
+Case sensitivity: bool(true)
+Non existent function: bool(false)
+Method: bool(false)
+===Done===
diff --git a/Zend/tests/function_exists_error.phpt b/Zend/tests/function_exists_error.phpt
new file mode 100644 (file)
index 0000000..a4c1294
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Test function_exists() function : error conditions 
+--INI--
+--FILE--
+<?php
+/* 
+ * proto bool function_exists(string function_name)
+ * Function is implemented in Zend/zend_builtin_functions.c
+*/ 
+
+echo "*** Testing function_exists() : error conditions ***\n";
+
+$arg_0 = "ABC";
+$extra_arg = 1;
+
+echo "\nToo many arguments\n";
+var_dump(function_exists($arg_0, $extra_arg));
+
+echo "\nToo few arguments\n";
+var_dump(function_exists());
+
+?>
+===Done===
+--EXPECTF--
+*** Testing function_exists() : error conditions ***
+
+Too many arguments
+
+Warning: Wrong parameter count for function_exists() in %s on line %d
+NULL
+
+Too few arguments
+
+Warning: Wrong parameter count for function_exists() in %s on line %d
+NULL
+===Done===
+
diff --git a/Zend/tests/function_exists_variation1.phpt b/Zend/tests/function_exists_variation1.phpt
new file mode 100644 (file)
index 0000000..70cf6be
--- /dev/null
@@ -0,0 +1,135 @@
+--TEST--
+Test function_exists() function : usage variations - test values for $str argument
+--FILE--
+<?php
+
+/* 
+ * proto bool function_exists(string function_name)
+ * Function is implemented in Zend/zend_builtin_functions.c
+*/ 
+
+echo "*** Testing function_exists() function: with unexpected inputs for 'str' argument ***\n";
+
+//get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+//defining a class
+class sample  {
+  public function __toString() {
+    return "sample object";
+  } 
+}
+
+//getting the resource
+$file_handle = fopen(__FILE__, "r");
+
+// array with different values for $str
+$inputs =  array (
+
+  // integer values
+  0,
+  1,
+  255,
+  256,
+  PHP_INT_MAX,
+  -PHP_INT_MAX,
+
+  // float values
+  10.5,
+  -20.5,
+  10.1234567e10,
+
+  // array values
+  array(),
+  array(0),
+  array(1, 2),
+
+  // boolean values
+  true,
+  false,
+  TRUE,
+  FALSE,
+
+  // null values
+  NULL,
+  null,
+
+  // objects
+  new sample(),
+
+  // resource
+  $file_handle,
+
+  // undefined variable
+  @$undefined_var,
+
+  // unset variable
+  @$unset_var
+);
+
+// loop through with each element of the $inputs array to test function_exists() function
+$count = 1;
+foreach($inputs as $input) {
+  echo "-- Iteration $count --\n";
+  var_dump( function_exists($input) );
+  $count ++;
+}
+
+fclose($file_handle);  //closing the file handle
+
+?>
+===Done===
+--EXPECTF--
+*** Testing function_exists() function: with unexpected inputs for 'str' argument ***
+-- Iteration 1 --
+bool(false)
+-- Iteration 2 --
+bool(false)
+-- Iteration 3 --
+bool(false)
+-- Iteration 4 --
+bool(false)
+-- Iteration 5 --
+bool(false)
+-- Iteration 6 --
+bool(false)
+-- Iteration 7 --
+bool(false)
+-- Iteration 8 --
+bool(false)
+-- Iteration 9 --
+bool(false)
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+bool(false)
+-- Iteration 13 --
+bool(false)
+-- Iteration 14 --
+bool(false)
+-- Iteration 15 --
+bool(false)
+-- Iteration 16 --
+bool(false)
+-- Iteration 17 --
+bool(false)
+-- Iteration 18 --
+bool(false)
+-- Iteration 19 --
+bool(false)
+-- Iteration 20 --
+bool(false)
+-- Iteration 21 --
+bool(false)
+-- Iteration 22 --
+bool(false)
+===Done===
diff --git a/Zend/tests/get_defined_functions_basic.phpt b/Zend/tests/get_defined_functions_basic.phpt
new file mode 100644 (file)
index 0000000..a849e32
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+get_defined_functions() function : basic functionality 
+--FILE--
+<?php
+
+/* Prototype  : array get_defined_functions  ( void  )
+ * Description: Gets an array of all defined functions.
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+echo "*** Testing get_defined_functions() : basic functionality ***\n";
+
+function foo() {}
+
+// mixed case function
+function HelloWorld() {}
+
+Class C {
+       function f1() {}
+       static function f2() {}
+}
+
+$func = get_defined_functions();
+
+if (!is_array($func)) {
+       echo "TEST FAILED: return type not an array\n";
+}
+
+
+if (!is_array($func["internal"])) {
+       echo "TEST FAILED: no element in result array with key 'internal'\n";
+}      
+
+$internal = $func["internal"];
+
+//check for a few core functions
+if (!in_array("cos", $internal) || !in_array("strlen", $internal)) {
+       echo "TEST FAILED: missing elements from 'internal' array\n";
+       var_dump($internal);
+} 
+
+if (!is_array($func["user"])) {
+       echo "TEST FAILED: no element in result array with key 'user'\n";
+}
+
+$user = $func["user"];
+if (count($user) == 2 && in_array("foo", $user) && in_array("helloworld", $user)) {
+       echo "TEST PASSED\n";
+} else {
+       echo "TEST FAILED: missing elements from 'user' array\n";
+       var_dump($user);
+}      
+
+?>
+===Done===
+--EXPECT--
+*** Testing get_defined_functions() : basic functionality ***
+TEST PASSED
+===Done===
diff --git a/Zend/tests/get_defined_functions_error.phpt b/Zend/tests/get_defined_functions_error.phpt
new file mode 100644 (file)
index 0000000..0626ed0
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Test get_defined_functions() function : error conditions 
+--FILE--
+<?php
+
+/* Prototype  : array get_defined_functions  ( void  )
+ * Description: Gets an array of all defined functions.
+ * Source code: Zend/zend_builtin_functions.c
+*/
+
+
+echo "*** Testing get_defined_functions() : error conditions ***\n";
+
+
+echo "\n-- Testing get_defined_functions() function with more than expected no. of arguments --\n";
+$extra_arg = 10;
+var_dump( get_defined_functions($extra_arg) );
+
+?> 
+===Done===
+--EXPECTF--
+*** Testing get_defined_functions() : error conditions ***
+
+-- Testing get_defined_functions() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for get_defined_functions() in %s on line %d
+NULL
+===Done===