From: Felix De Vliegher Date: Fri, 8 Aug 2008 12:42:40 +0000 (+0000) Subject: MFB: Tests for ReflectionMethod::getClosure() and ReflectionFunction::getClosure() X-Git-Tag: BEFORE_HEAD_NS_CHANGE~813 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=934dd2e32621644274be79723b12bc210586238a;p=php MFB: Tests for ReflectionMethod::getClosure() and ReflectionFunction::getClosure() --- diff --git a/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt b/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt new file mode 100644 index 0000000000..832d31c5f5 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test ReflectionFunction::getClosure() function : basic functionality +--FILE-- +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=== diff --git a/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt b/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt new file mode 100644 index 0000000000..76851ea5cc --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getClosure_error.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ReflectionFunction::getClosure() function : error functionality +--FILE-- +getClosure('bar'); + +?> +===DONE=== +--EXPECTF-- +*** Testing ReflectionFunction::getClosure() : error conditions *** + +Warning: Wrong parameter count for ReflectionFunction::getClosure() in %s on line %d +===DONE=== diff --git a/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt b/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt new file mode 100644 index 0000000000..d8bdbe110c --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test ReflectionMethod::getClosure() function : basic functionality +--FILE-- +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=== diff --git a/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt b/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt new file mode 100644 index 0000000000..a54b09de29 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test ReflectionMethod::getClosure() function : error functionality +--FILE-- +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===