Browse Source

MFB: Tests for ReflectionMethod::getClosure() and ReflectionFunction::getClosure()

experimental/first_unicode_implementation
Felix De Vliegher 18 years ago
parent
commit
934dd2e326
  1. 37
      ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt
  2. 27
      ext/reflection/tests/ReflectionFunction_getClosure_error.phpt
  3. 55
      ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt
  4. 73
      ext/reflection/tests/ReflectionMethod_getClosure_error.phpt

37
ext/reflection/tests/ReflectionFunction_getClosure_basic.phpt

@ -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===

27
ext/reflection/tests/ReflectionFunction_getClosure_error.phpt

@ -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===

55
ext/reflection/tests/ReflectionMethod_getClosure_basic.phpt

@ -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===

73
ext/reflection/tests/ReflectionMethod_getClosure_error.phpt

@ -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===
Loading…
Cancel
Save