MediaWiki  master
MWFunctionTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class MWFunctionTest extends MediaWikiTestCase {
00004         
00005         function testCallUserFuncWorkarounds() {
00006                 $this->assertEquals( 
00007                         call_user_func( array( 'MWFunctionTest', 'someMethod' ) ),
00008                         MWFunction::call( 'MWFunctionTest::someMethod' )
00009                 );
00010                 $this->assertEquals( 
00011                         call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ),
00012                         MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' )
00013                 );
00014 
00015                 $this->assertEquals( 
00016                         call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ),
00017                         MWFunction::callArray( 'MWFunctionTest::someMethod', array() )
00018                 );
00019                 $this->assertEquals( 
00020                         call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ),
00021                         MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) )
00022                 );
00023         }
00024         
00025         function testNewObjFunction() {
00026                 $arg1 = 'Foo';
00027                 $arg2 = 'Bar';
00028                 $arg3 = array( 'Baz' );
00029                 $arg4 = new ExampleObject;
00030 
00031                 $args = array( $arg1, $arg2, $arg3, $arg4 );
00032 
00033                 $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 );
00034                 $this->assertEquals( 
00035                         MWFunction::newObj( 'MWBlankClass', $args )->args, 
00036                         $newObject->args
00037                 );
00038 
00039                 $this->assertEquals( 
00040                         MWFunction::newObj( 'MWBlankClass', $args, true )->args, 
00041                         $newObject->args,
00042                         'Works even with PHP version < 5.1.3'
00043                 );
00044         }
00045         
00049         function testCallingParentFails() {
00050                 MWFunction::call( 'parent::foo' );
00051         }
00052         
00056         function testCallingSelfFails() {
00057                 MWFunction::call( 'self::foo' );
00058         }
00059         
00060         public static function someMethod() {
00061                 return func_get_args();
00062         }
00063         
00064 }
00065 
00066 class MWBlankClass {
00067 
00068         public $args = array();
00069 
00070         function __construct( $arg1, $arg2, $arg3, $arg4 ) {
00071                 $this->args = array( $arg1, $arg2, $arg3, $arg4 );
00072         }
00073 }
00074 
00075 class ExampleObject {
00076 }