r105883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105882‎ | r105883 | r105884 >
Date:15:02, 12 December 2011
Author:hashar
Status:ok
Tags:
Comment:
use __call() to instantly have some new fresh helpers

Only for MWNamespaceTest :-)
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php
@@ -535,5 +535,35 @@
536536 $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) );
537537
538538 }
 539+
 540+ ####### HELPERS ###########################################################
 541+ function __call( $method, $args ) {
 542+ // Call the real method if it exists
 543+ if( method_exists($this, $method ) ) {
 544+ return $this->$method( $args );
 545+ }
 546+
 547+ if( preg_match( '/^assert(Has|Is)(Not|)(Subject|Talk)$/', $method, $m ) ) {
 548+ # Interprets arguments:
 549+ $ns = $args[0];
 550+ $msg = isset($args[1]) ? $args[1] : " dummy message";
 551+
 552+ # Forge the namespace constant name:
 553+ $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) );
 554+ # ... and the MWNamespace method name
 555+ $nsMethod = strtolower( $m[1] ) . $m[3];
 556+
 557+ $expect = ($m[2] === '');
 558+ $expect_name = $expect ? 'TRUE' : 'FALSE';
 559+
 560+ return $this->assertEquals( $expect,
 561+ MWNamespace::$nsMethod( $ns, $msg ),
 562+ "MWNamespace::$nsMethod( $ns_name ) should returns $expect_name"
 563+ );
 564+ }
 565+
 566+ throw new Exception( __METHOD__ . " could not find a method named $method\n" );
 567+ }
 568+
539569 }
540570

Follow-up revisions

RevisionCommit summaryAuthorDate
r105889use MWNamespaceTest helpers based on __call()...hashar15:26, 12 December 2011

Status & tagging log