felixdv Fri Aug 8 12:42:40 2008 UTC Modified files: /php-src/ext/reflection/tests ReflectionMethod_getClosure_basic.phpt ReflectionMethod_getClosure_error.phpt ReflectionFunction_getClosure_basic.phpt ReflectionFunction_getClosure_error.phpt Log: MFB: Tests for ReflectionMethod::getClosure() and ReflectionFunction::getClosure() http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt diff -u /dev/null php-src/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt:1.2 --- /dev/null Fri Aug 8 12:42:40 2008 +++ php-src/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt Fri Aug 8 12:42:40 2008 @@ -0,0 +1,55 @@ +--TEST-- +Test ReflectionMethod::getClosure() function : basic functionality +--FILE-- +<?php +/* Prototype : public mixed ReflectionFunction::getClosure() + * Description: Returns a dynamically created closure for the method + * Source code: ext/reflection/php_reflection.c + * Alias to functions: + */ + +echo "*** Testing ReflectionMethod::getClosure() : basic functionality ***\n"; + +class StaticExample +{ + static function foo() + { + var_dump( "Static Example class, Hello World!" ); + } +} + +class Example +{ + public $bar = 42; + public function foo() + { + var_dump( "Example class, bar: " . $this->bar ); + } +} + +// Initialize classes +$class = new ReflectionClass( 'Example' ); +$staticclass = new ReflectionClass( 'StaticExample' ); +$object = new Example(); +$fakeobj = new StdClass(); + + +$method = $staticclass->getMethod( 'foo' ); +$closure = $method->getClosure(); +$closure(); + +$method = $class->getMethod( 'foo' ); + +$closure = $method->getClosure( $object ); +$closure(); +$object->bar = 34; +$closure(); + +?> +===DONE=== +--EXPECTF-- +*** Testing ReflectionMethod::getClosure() : basic functionality *** +%unicode|string%(34) "Static Example class, Hello World!" +%unicode|string%(22) "Example class, bar: 42" +%unicode|string%(22) "Example class, bar: 34" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt diff -u /dev/null php-src/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt:1.2 --- /dev/null Fri Aug 8 12:42:40 2008 +++ php-src/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt Fri Aug 8 12:42:40 2008 @@ -0,0 +1,73 @@ +--TEST-- +Test ReflectionMethod::getClosure() function : error functionality +--FILE-- +<?php +/* Prototype : public mixed ReflectionFunction::getClosure() + * Description: Returns a dynamically created closure for the method + * Source code: ext/reflection/php_reflection.c + * Alias to functions: + */ + +echo "*** Testing ReflectionMethod::getClosure() : error conditions ***\n"; + +class StaticExample +{ + static function foo() + { + var_dump( "Static Example class, Hello World!" ); + } +} + +class Example +{ + public $bar = 42; + public function foo() + { + var_dump( "Example class, bar: " . $this->bar ); + } +} + +// Initialize classes +$class = new ReflectionClass( 'Example' ); +$staticclass = new ReflectionClass( 'StaticExample' ); +$method = $class->getMethod( 'foo' ); +$staticmethod = $staticclass->getMethod( 'foo' ); +$object = new Example(); +$fakeobj = new StdClass(); + +echo "\n-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --\n"; +var_dump( $staticmethod->getClosure( 'foobar' ) ); +var_dump( $staticmethod->getClosure( 'foo', 'bar' ) ); +var_dump( $method->getClosure( $object, 'foobar' ) ); + +echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n"; +$closure = $method->getClosure(); + +echo "\n-- Testing ReflectionMethod::getClosure() function with Zero arguments --\n"; +try { + var_dump( $method->getClosure( $fakeobj ) ); +} catch( Exception $e ) { + var_dump( $e->getMessage() ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing ReflectionMethod::getClosure() : error conditions *** + +-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments -- +object(Closure)#%d (0) { +} +object(Closure)#%d (0) { +} + +Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +-- Testing ReflectionMethod::getClosure() function with Zero arguments -- + +Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 0 given in %s on line %d + +-- Testing ReflectionMethod::getClosure() function with Zero arguments -- +%unicode|string%(72) "Given object is not an instance of the class this method was declared in" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt diff -u /dev/null php-src/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt:1.2 --- /dev/null Fri Aug 8 12:42:40 2008 +++ php-src/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt Fri Aug 8 12:42:40 2008 @@ -0,0 +1,37 @@ +--TEST-- +Test ReflectionFunction::getClosure() function : basic functionality +--FILE-- +<?php +/* Prototype : public mixed ReflectionFunction::getClosure() + * Description: Returns a dynamically created closure for the function + * Source code: ext/reflection/php_reflection.c + * Alias to functions: + */ + +echo "*** Testing ReflectionFunction::getClosure() : basic functionality ***\n"; + +function foo() +{ + var_dump( "Inside foo function" ); +} + +function bar( $arg ) +{ + var_dump( "Arg is " . $arg ); +} + +$func = new ReflectionFunction( 'foo' ); +$closure = $func->getClosure(); +$closure(); + +$func = new ReflectionFunction( 'bar' ); +$closure = $func->getClosure(); +$closure( 'succeeded' ); + +?> +===DONE=== +--EXPECTF-- +*** Testing ReflectionFunction::getClosure() : basic functionality *** +%unicode|string%(19) "Inside foo function" +%unicode|string%(16) "Arg is succeeded" +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt diff -u /dev/null php-src/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt:1.2 --- /dev/null Fri Aug 8 12:42:40 2008 +++ php-src/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt Fri Aug 8 12:42:40 2008 @@ -0,0 +1,27 @@ +--TEST-- +Test ReflectionFunction::getClosure() function : error functionality +--FILE-- +<?php +/* Prototype : public mixed ReflectionFunction::getClosure() + * Description: Returns a dynamically created closure for the function + * Source code: ext/reflection/php_reflection.c + * Alias to functions: + */ + +echo "*** Testing ReflectionFunction::getClosure() : error conditions ***\n"; + +function foo() +{ + var_dump( "Inside foo function" ); +} + +$func = new ReflectionFunction( 'foo' ); +$closure = $func->getClosure('bar'); + +?> +===DONE=== +--EXPECTF-- +*** Testing ReflectionFunction::getClosure() : error conditions *** + +Warning: Wrong parameter count for ReflectionFunction::getClosure() in %s on line %d +===DONE===
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php