kraghuba Mon Oct 22 11:17:18 2007 UTC Modified files: /php-src/ext/standard/tests/array array_filter_object.phpt Log: more testcases for array_filter() function http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_filter_object.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/array/array_filter_object.phpt diff -u /dev/null php-src/ext/standard/tests/array/array_filter_object.phpt:1.2 --- /dev/null Mon Oct 22 11:17:18 2007 +++ php-src/ext/standard/tests/array/array_filter_object.phpt Mon Oct 22 11:17:18 2007 @@ -0,0 +1,210 @@ +--TEST-- +Test array_filter() function : object functionality +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* This file uses 'input' array with different types of objects and passes + * it to array_filter() to test object functionality + * i.e. object of simple class with members and functions + * object of empty class + * object of child class extending abstract class + * object of class containing static member + */ + +echo "*** Testing array_filter() : object functionality ***\n"; + +// simple class with members - variable and method +class SimpleClass +{ + public $var1 = 10; + public function check() { + return $var1; + } +} + +// class without members +class EmptyClass +{ +} + +// abstract class +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyMethod(); +} + +// class deriving above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyMethod() { + echo "defined in child"; + } +} + +// class with final method +class FinalClass +{ + private $var4; + final function finalMethod() { + echo 'This can not be overloaded'; + } +} + +// class with static members +class StaticClass +{ + static $var5 = 5; + public static function staticMethod() { + echo 'this is static method'; + } +} + +// Callback function which returns always true +function always_true($input) +{ + return true; +} + +// Callback function which returns always false +function always_false($input) +{ + return false; +} + +// 'input' array containing objects as elements +$input = array( + new SimpleClass(), + new EmptyClass(), + new ChildClass(), + new FinalClass(), + new StaticClass() +); + + +// with default callback +var_dump( array_filter($input) ); + +// with always_true callback function +var_dump( array_filter($input, "always_true") ); + +// with always_false callback function +var_dump( array_filter($input, "always_false") ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : object functionality *** +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(0) { +} +Done +--UEXPECTF-- +*** Testing array_filter() : object functionality *** +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + [u"var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + [u"var3":u"ChildClass":private]=> + NULL + [u"var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + [u"var4":u"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + [u"var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + [u"var3":u"ChildClass":private]=> + NULL + [u"var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + [u"var4":u"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(0) { +} +Done
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php