From: Antoine Musso Date: Mon, 12 Dec 2011 15:02:47 +0000 (+0000) Subject: use __call() to instantly have some new fresh helpers X-Git-Tag: 1.31.0-rc.0~26047 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=90a5c227dc06c8f5f4a9a8f5e0b086c0be3381e3;p=lhc%2Fweb%2Fwiklou.git use __call() to instantly have some new fresh helpers Only for MWNamespaceTest :-) --- diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index 1e7c20dabf..be917d8443 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -535,5 +535,35 @@ class MWNamespaceTest extends MediaWikiTestCase { $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) ); } + + ####### HELPERS ########################################################### + function __call( $method, $args ) { + // Call the real method if it exists + if( method_exists($this, $method ) ) { + return $this->$method( $args ); + } + + if( preg_match( '/^assert(Has|Is)(Not|)(Subject|Talk)$/', $method, $m ) ) { + # Interprets arguments: + $ns = $args[0]; + $msg = isset($args[1]) ? $args[1] : " dummy message"; + + # Forge the namespace constant name: + $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) ); + # ... and the MWNamespace method name + $nsMethod = strtolower( $m[1] ) . $m[3]; + + $expect = ($m[2] === ''); + $expect_name = $expect ? 'TRUE' : 'FALSE'; + + return $this->assertEquals( $expect, + MWNamespace::$nsMethod( $ns, $msg ), + "MWNamespace::$nsMethod( $ns_name ) should returns $expect_name" + ); + } + + throw new Exception( __METHOD__ . " could not find a method named $method\n" ); + } + }