diff options
| author | andy wharmby <wharmby@php.net> | 2009-06-16 08:59:39 +0000 |
|---|---|---|
| committer | andy wharmby <wharmby@php.net> | 2009-06-16 08:59:39 +0000 |
| commit | f0f302fe7fe1fd78623e3a6527410d1e28801efe (patch) | |
| tree | 5434bb131fef86fe6cd5fd40f78c18bacb51949f | |
| parent | a2acaa7fcd5407f4a2fcf067069b0d5d82d8e5a6 (diff) | |
| download | php-git-f0f302fe7fe1fd78623e3a6527410d1e28801efe.tar.gz | |
New class related tests. Tested on Windows, Linux and Linux 64. Tests written by Iain Lewis
16 files changed, 1227 insertions, 0 deletions
diff --git a/ext/standard/tests/class_object/AutoInterface.inc b/ext/standard/tests/class_object/AutoInterface.inc new file mode 100644 index 0000000000..f1e5b1f58f --- /dev/null +++ b/ext/standard/tests/class_object/AutoInterface.inc @@ -0,0 +1,5 @@ +<?php + +Interface AutoInterface {} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/AutoLoaded.inc b/ext/standard/tests/class_object/AutoLoaded.inc new file mode 100644 index 0000000000..52e6671ddc --- /dev/null +++ b/ext/standard/tests/class_object/AutoLoaded.inc @@ -0,0 +1,5 @@ +<?php + +class AutoLoaded {} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/AutoTest.inc b/ext/standard/tests/class_object/AutoTest.inc new file mode 100644 index 0000000000..0627096fff --- /dev/null +++ b/ext/standard/tests/class_object/AutoTest.inc @@ -0,0 +1,13 @@ +<?php + +class autoTest { + public static $bob = "bob"; + + public function __get($name) { + echo "attempt to access $name\n"; + return "foo"; + } + +} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_vars_error.phpt b/ext/standard/tests/class_object/get_class_vars_error.phpt new file mode 100644 index 0000000000..0399e6023a --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test get_class_vars() function : error conditions +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_vars() : error conditions ***\n"; + + +//Test get_class_vars with one more than the expected number of arguments +echo "\n-- Testing get_class_vars() function with more than expected no. of arguments --\n"; +$obj = new stdclass(); +$extra_arg = 10; +var_dump(get_class_vars($obj,$extra_arg) ); + +// Testing get_class_vars with one less than the expected number of arguments +echo "\n-- Testing get_class_vars() function with less than expected no. of arguments --\n"; +var_dump(get_class_vars()); + +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : error conditions *** + +-- Testing get_class_vars() function with more than expected no. of arguments -- + +Warning: get_class_vars() expects exactly 1 parameter, 2 given in %sget_class_vars_error.php on line %d +NULL + +-- Testing get_class_vars() function with less than expected no. of arguments -- + +Warning: get_class_vars() expects exactly 1 parameter, 0 given in %sget_class_vars_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_vars_variation1.phpt b/ext/standard/tests/class_object/get_class_vars_variation1.phpt new file mode 100644 index 0000000000..649e9ae5af --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_variation1.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test get_class_vars() function : usage variation +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_vars() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for method_name + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( get_class_vars($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--int indexed array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--associative array-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--nested arrays-- + +Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--instance of classWithToString-- +bool(false) + +--instance of classWithoutToString-- + +Warning: get_class_vars() expects parameter 1 to be string, object given in %sget_class_vars_variation1.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE=== diff --git a/ext/standard/tests/class_object/get_class_vars_variation2.phpt b/ext/standard/tests/class_object/get_class_vars_variation2.phpt new file mode 100644 index 0000000000..fad5716745 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_vars_variation2.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test get_class_vars() function : testing visibility +--FILE-- +<?php +/* Prototype : array get_class_vars(string class_name) + * Description: Returns an array of default properties of the class. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class Ancestor { + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +class Tester extends Ancestor { + public $pub = "public var"; + protected $prot = "protected var"; + private $priv = "private var"; + + static public $pubs = "public static var"; + static protected $prots = "protected static var"; + static private $privs = "private static var"; + + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +class Child extends Tester { + function test() { + var_dump(get_class_vars("Tester")); + } + + static function testStatic() { + var_dump(get_class_vars("Tester")); + } +} + +echo "*** Testing get_class_vars() : testing visibility\n"; + +echo "\n-- From global context --\n"; +var_dump(get_class_vars("Tester")); + +echo "\n-- From inside an object instance --\n"; +$instance = new Tester(); +$instance->test(); + +echo "\n-- From a static context --\n"; +Tester::testStatic(); + + +echo "\n-- From inside an parent object instance --\n"; +$parent = new Ancestor(); +$parent->test(); + +echo "\n-- From a parents static context --\n"; +Ancestor::testStatic(); + + +echo "\n-- From inside a child object instance --\n"; +$child = new Child(); +$child->test(); + +echo "\n-- From a child's static context --\n"; +Child::testStatic(); +?> +===DONE=== +--EXPECTF-- +*** Testing get_class_vars() : testing visibility + +-- From global context -- +array(2) { + ["pub"]=> + string(10) "public var" + ["pubs"]=> + string(17) "public static var" +} + +-- From inside an object instance -- +array(6) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["priv"]=> + string(11) "private var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" + ["privs"]=> + string(18) "private static var" +} + +-- From a static context -- +array(6) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["priv"]=> + string(11) "private var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" + ["privs"]=> + string(18) "private static var" +} + +-- From inside an parent object instance -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From a parents static context -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From inside a child object instance -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} + +-- From a child's static context -- +array(4) { + ["pub"]=> + string(10) "public var" + ["prot"]=> + string(13) "protected var" + ["pubs"]=> + string(17) "public static var" + ["prots"]=> + string(20) "protected static var" +} +===DONE=== diff --git a/ext/standard/tests/class_object/get_declared_classes_variation1.phpt b/ext/standard/tests/class_object/get_declared_classes_variation1.phpt new file mode 100644 index 0000000000..259f5dc0f8 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_declared_classes() function : testing autoloaded classes +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_classes() : testing autoloaded classes ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- before instance is declared --\n"; +var_dump(in_array('AutoLoaded', get_declared_classes())); + +echo "\n-- after instance is declared --\n"; +$class = new AutoLoaded(); +var_dump(in_array('AutoLoaded', get_declared_classes())); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing get_declared_classes() : testing autoloaded classes *** + +-- before instance is declared -- +bool(false) + +-- after instance is declared -- +bool(true) + +DONE diff --git a/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt b/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt new file mode 100644 index 0000000000..56e6161b23 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_declared_interfaces() function : autoloading of interfaces +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_interfaces() : autoloading of interfaces ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- before interface is used --\n"; +var_dump(in_array('AutoInterface', get_declared_interfaces())); + + +echo "\n-- after interface is used --\n"; +class Implementor implements AutoInterface {} +var_dump(in_array('AutoInterface', get_declared_interfaces())); + +echo "\nDONE\n"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : autoloading of interfaces *** + +-- before interface is used -- +bool(false) + +-- after interface is used -- +bool(true) + +DONE diff --git a/ext/standard/tests/class_object/interface_exists_error.phpt b/ext/standard/tests/class_object/interface_exists_error.phpt new file mode 100644 index 0000000000..bf95a43050 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test interface_exists() function : error conditions +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing interface_exists() function with Zero arguments --\n"; +var_dump( interface_exists() ); + +//Test interface_exists with one more than the expected number of arguments +echo "\n-- Testing interface_exists() function with more than expected no. of arguments --\n"; +$classname = 'string_val'; +$autoload = true; +$extra_arg = 10; +var_dump( interface_exists($classname, $autoload, $extra_arg) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : error conditions *** + +-- Testing interface_exists() function with Zero arguments -- + +Warning: interface_exists() expects at least 1 parameter, 0 given in %sinterface_exists_error.php on line %d +NULL + +-- Testing interface_exists() function with more than expected no. of arguments -- + +Warning: interface_exists() expects at most 2 parameters, 3 given in %sinterface_exists_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation1.phpt b/ext/standard/tests/class_object/interface_exists_variation1.phpt new file mode 100644 index 0000000000..34d0e1e6b0 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation1.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test interface_exists() function : usage variation +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$autoload = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for classname + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( interface_exists($value, $autoload) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--int indexed array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--associative array-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--nested arrays-- + +Warning: interface_exists() expects parameter 1 to be string, array given in %sinterface_exists_variation1.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--instance of classWithToString-- +bool(false) + +--instance of classWithoutToString-- + +Warning: interface_exists() expects parameter 1 to be string, object given in %sinterface_exists_variation1.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation2.phpt b/ext/standard/tests/class_object/interface_exists_variation2.phpt new file mode 100644 index 0000000000..4137d8a0f9 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation2.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test interface_exists() function : usage variation +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$classname = 'aBogusInterfaceName'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for autoload + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( interface_exists($classname, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing interface_exists() : usage variation *** + +--int 0-- +bool(false) + +--int 1-- +bool(false) + +--int 12345-- +bool(false) + +--int -12345-- +bool(false) + +--float 10.5-- +bool(false) + +--float -10.5-- +bool(false) + +--float 12.3456789000e10-- +bool(false) + +--float -12.3456789000e10-- +bool(false) + +--float .5-- +bool(false) + +--empty array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--int indexed array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--associative array-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--nested arrays-- + +Warning: interface_exists() expects parameter 2 to be boolean, array given in %sinterface_exists_variation2.php on line %d +NULL + +--uppercase NULL-- +bool(false) + +--lowercase null-- +bool(false) + +--lowercase true-- +bool(false) + +--lowercase false-- +bool(false) + +--uppercase TRUE-- +bool(false) + +--uppercase FALSE-- +bool(false) + +--empty string DQ-- +bool(false) + +--empty string SQ-- +bool(false) + +--string DQ-- +bool(false) + +--string SQ-- +bool(false) + +--mixed case string-- +bool(false) + +--heredoc-- +bool(false) + +--instance of classWithToString-- + +Warning: interface_exists() expects parameter 2 to be boolean, object given in %sinterface_exists_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: interface_exists() expects parameter 2 to be boolean, object given in %sinterface_exists_variation2.php on line %d +NULL + +--undefined var-- +bool(false) + +--unset var-- +bool(false) +===DONE=== diff --git a/ext/standard/tests/class_object/interface_exists_variation3.phpt b/ext/standard/tests/class_object/interface_exists_variation3.phpt new file mode 100644 index 0000000000..d25d74bc41 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation3.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test interface_exists() function : autoloaded interface +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : autoloaded interface ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\n-- no autoloading --\n"; +var_dump(interface_exists("AutoInterface", false)); + +echo "\n-- with autoloading --\n"; +var_dump(interface_exists("AutoInterface", true)); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing interface_exists() : autoloaded interface *** + +-- no autoloading -- +bool(false) + +-- with autoloading -- +bool(true) + +DONE
\ No newline at end of file diff --git a/ext/standard/tests/class_object/interface_exists_variation4.phpt b/ext/standard/tests/class_object/interface_exists_variation4.phpt new file mode 100644 index 0000000000..c059805623 --- /dev/null +++ b/ext/standard/tests/class_object/interface_exists_variation4.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test interface_exists() function : test autoload default value +--FILE-- +<?php +/* Prototype : bool interface_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing interface_exists() : test autoload default value ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + + +var_dump(interface_exists("AutoInterface")); + +echo "\nDONE\n"; + +?> +--EXPECTF-- +*** Testing interface_exists() : test autoload default value *** +bool(true) + +DONE
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt new file mode 100644 index 0000000000..72a02a0b2b --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_004.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 1 with valid class in arg 2. +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'stdClass'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(69) +Error: 8 - Undefined variable: unset_var, %s(72) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value string +In __autoload(string) +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value String +In __autoload(String) +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/property_exists_error.phpt b/ext/standard/tests/class_object/property_exists_error.phpt new file mode 100644 index 0000000000..e40e08b32a --- /dev/null +++ b/ext/standard/tests/class_object/property_exists_error.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test property_exists() function : error conditions +--FILE-- +<?php +/* Prototype : bool property_exists(mixed object_or_class, string property_name) + * Description: Checks if the object or class has a property + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing property_exists() : error conditions ***\n"; + +$object_or_class = "obj"; +$property_name = 'string_val'; +$extra_arg = 10; + + +echo "\n-- Testing property_exists() function with more than expected no. of arguments --\n"; +var_dump( property_exists($object_or_class, $property_name, $extra_arg) ); + + +echo "\n-- Testing property_exists() function with less than expected no. of arguments --\n"; +var_dump( property_exists($object_or_class) ); + +echo "\n-- Testing property_exists() function with incorrect arguments --\n"; +var_dump( property_exists(10, $property_name) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing property_exists() : error conditions *** + +-- Testing property_exists() function with more than expected no. of arguments -- + +Warning: property_exists() expects exactly 2 parameters, 3 given in %sproperty_exists_error.php on line %d +NULL + +-- Testing property_exists() function with less than expected no. of arguments -- + +Warning: property_exists() expects exactly 2 parameters, 1 given in %sproperty_exists_error.php on line %d +NULL + +-- Testing property_exists() function with incorrect arguments -- + +Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/class_object/property_exists_variation1.phpt b/ext/standard/tests/class_object/property_exists_variation1.phpt new file mode 100644 index 0000000000..1505a4bafa --- /dev/null +++ b/ext/standard/tests/class_object/property_exists_variation1.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test property_exists() function : class auto loading +--FILE-- +<?php +/* Prototype : bool property_exists(mixed object_or_class, string property_name) + * Description: Checks if the object or class has a property + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing property_exists() : class auto loading ***\n"; + +function __autoload($class_name) { + require_once $class_name . '.inc'; +} + +echo "\ntesting property in autoloaded class\n"; +var_dump(property_exists("AutoTest", "bob")); + +echo "\ntesting __get magic method\n"; +var_dump(property_exists("AutoTest", "foo")); + +?> +===DONE=== +--EXPECTF-- +*** Testing property_exists() : class auto loading *** + +testing property in autoloaded class +bool(true) + +testing __get magic method +bool(false) +===DONE===
\ No newline at end of file |
