mirror of
https://github.com/php/php-src.git
synced 2024-09-23 10:57:26 +00:00
New class related tests. Tested on Windows, Linux and Linux 64. Tests written by Iain Lewis
This commit is contained in:
parent
a2acaa7fcd
commit
f0f302fe7f
5
ext/standard/tests/class_object/AutoInterface.inc
Normal file
5
ext/standard/tests/class_object/AutoInterface.inc
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
Interface AutoInterface {}
|
||||
|
||||
?>
|
5
ext/standard/tests/class_object/AutoLoaded.inc
Normal file
5
ext/standard/tests/class_object/AutoLoaded.inc
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class AutoLoaded {}
|
||||
|
||||
?>
|
13
ext/standard/tests/class_object/AutoTest.inc
Normal file
13
ext/standard/tests/class_object/AutoTest.inc
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class autoTest {
|
||||
public static $bob = "bob";
|
||||
|
||||
public function __get($name) {
|
||||
echo "attempt to access $name\n";
|
||||
return "foo";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
38
ext/standard/tests/class_object/get_class_vars_error.phpt
Normal file
38
ext/standard/tests/class_object/get_class_vars_error.phpt
Normal file
@ -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===
|
181
ext/standard/tests/class_object/get_class_vars_variation1.phpt
Normal file
181
ext/standard/tests/class_object/get_class_vars_variation1.phpt
Normal file
@ -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===
|
168
ext/standard/tests/class_object/get_class_vars_variation2.phpt
Normal file
168
ext/standard/tests/class_object/get_class_vars_variation2.phpt
Normal file
@ -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===
|
@ -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
|
@ -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
|
38
ext/standard/tests/class_object/interface_exists_error.phpt
Normal file
38
ext/standard/tests/class_object/interface_exists_error.phpt
Normal file
@ -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===
|
184
ext/standard/tests/class_object/interface_exists_variation1.phpt
Normal file
184
ext/standard/tests/class_object/interface_exists_variation1.phpt
Normal file
@ -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===
|
204
ext/standard/tests/class_object/interface_exists_variation2.phpt
Normal file
204
ext/standard/tests/class_object/interface_exists_variation2.phpt
Normal file
@ -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===
|
@ -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
|
@ -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
|
@ -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
|
47
ext/standard/tests/class_object/property_exists_error.phpt
Normal file
47
ext/standard/tests/class_object/property_exists_error.phpt
Normal file
@ -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===
|
@ -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===
|
Loading…
Reference in New Issue
Block a user