From 3589532db41e32bd09d6814674f7afbb0fe65e34 Mon Sep 17 00:00:00 2001 From: X! Date: Sun, 2 Jan 2011 06:48:07 +0000 Subject: [PATCH] Per my comment on r68760: Make MWfunction class, complete with call_user_func helper functions that automatically make the callback PHP 5.1 compatible with the Class::Method syntax. Add Unit tests to supplement it. --- includes/AutoLoader.php | 1 + includes/MWFunction.php | 52 +++++++++++++++++++++++ includes/WebStart.php | 8 +--- maintenance/doMaintenance.php | 7 +-- tests/phpunit/includes/MWFunctionTest.php | 34 +++++++++++++++ 5 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 includes/MWFunction.php create mode 100644 tests/phpunit/includes/MWFunctionTest.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index fefa987c8a..2c7bfcabb0 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -166,6 +166,7 @@ $wgAutoloadLocalClasses = array( 'MessageCache' => 'includes/MessageCache.php', 'MimeMagic' => 'includes/MimeMagic.php', 'MWException' => 'includes/Exception.php', + 'MWFunction' => 'includes/MWFunction.php', 'MWHttpRequest' => 'includes/HttpFunctions.php', 'MWMemcached' => 'includes/memcached-client.php', 'MWNamespace' => 'includes/Namespace.php', diff --git a/includes/MWFunction.php b/includes/MWFunction.php new file mode 100644 index 0000000000..3622b69469 --- /dev/null +++ b/includes/MWFunction.php @@ -0,0 +1,52 @@ +assertEquals( + MWFunction::call( 'MWFunctionTest::someMethod' ), + call_user_func( array( 'MWFunctionTest', 'someMethod' ) ) + ); + $this->assertEquals( + MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' ), + call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ) + ); + + + + $this->assertEquals( + MWFunction::callArray( 'MWFunctionTest::someMethod', array() ), + call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ) + ); + $this->assertEquals( + MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) ), + call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ) + ); + + } + + public static function someMethod() { + return func_get_args(); + } + +} + -- 2.20.1