$needsResetDB = false;
$logName = get_class( $this ) . '::' . $this->getName( false );
- if( $this->needsDB() ) {
+ if ( $this->needsDB() ) {
// set up a DB connection for this test to use
self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
- self::$reuseDB = $this->getCliArg('reuse-db');
+ self::$reuseDB = $this->getCliArg( 'reuse-db' );
$this->db = wfGetDB( DB_MASTER );
$this->checkDbIsSupported();
- if( !self::$dbSetup ) {
+ if ( !self::$dbSetup ) {
wfProfileIn( $logName . ' (clone-db)' );
// switch to a temporary clone of the database
parent::run( $result );
wfProfileOut( $logName );
- if( $needsResetDB ) {
+ if ( $needsResetDB ) {
wfProfileIn( $logName . ' (reset-db)' );
$this->resetDB();
wfProfileOut( $logName . ' (reset-db)' );
*
* The obtained filename is enlisted to be removed upon tearDown
*
- * @returns string: absolute name of the temporary file
+ * @return string: absolute name of the temporary file
*/
protected function getNewTempFile() {
$fname = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
* The obtained directory is enlisted to be removed (recursively with all its contained
* files) upon tearDown.
*
- * @returns string: absolute name of the temporary directory
+ * @return string: absolute name of the temporary directory
*/
protected function getNewTempDirectory() {
// Starting of with a temporary /file/.
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
- while( $this->db->trxLevel() > 0 ) {
+ while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
- while( $this->db->trxLevel() > 0 ) {
+ while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
protected function setMwGlobals( $pairs, $value = null ) {
// Normalize (string, value) to an array
- if( is_string( $pairs ) ) {
+ if ( is_string( $pairs ) ) {
$pairs = array( $pairs => $value );
}
# Insert 0 user to prevent FK violations
# Anonymous user
$this->db->insert( 'user', array(
- 'user_id' => 0,
- 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
+ 'user_id' => 0,
+ 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
# Insert 0 page to prevent FK violations
# Blank page
* Empty all tables so they can be repopulated for tests
*/
private function resetDB() {
- if( $this->db ) {
- if ( $this->db->getType() == 'oracle' ) {
+ if ( $this->db ) {
+ if ( $this->db->getType() == 'oracle' ) {
if ( self::$useTemporaryTables ) {
wfGetLB()->closeAll();
$this->db = wfGetDB( DB_MASTER );
} else {
- foreach( $this->tablesUsed as $tbl ) {
- if( $tbl == 'interwiki') continue;
- $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
+ foreach ( $this->tablesUsed as $tbl ) {
+ if ( $tbl == 'interwiki' ) {
+ continue;
+ }
+ $this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ );
}
}
} else {
- foreach( $this->tablesUsed as $tbl ) {
- if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
+ foreach ( $this->tablesUsed as $tbl ) {
+ if ( $tbl == 'interwiki' || $tbl == 'user' ) {
+ continue;
+ }
$this->db->delete( $tbl, '*', __METHOD__ );
}
}
);
if ( method_exists( $this->suite, $func ) ) {
- return call_user_func_array( array( $this->suite, $func ), $args);
+ return call_user_func_array( array( $this->suite, $func ), $args );
} elseif ( isset( $compatibility[$func] ) ) {
- return call_user_func_array( array( $this, $compatibility[$func] ), $args);
+ return call_user_func_array( array( $this, $compatibility[$func] ), $args );
} else {
throw new MWException( "Called non-existant $func method on "
. get_class( $this ) );
}
protected function checkDbIsSupported() {
- if( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
+ if ( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
}
}
public function getCliArg( $offset ) {
- if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
+ if ( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
}
protected function assertSelect( $table, $fields, $condition, array $expectedRows ) {
if ( !$this->needsDB() ) {
throw new MWException( 'When testing database state, the test cases\'s needDB()' .
- ' method should return true. Use @group Database or $this->tablesUsed.');
+ ' method should return true. Use @group Database or $this->tablesUsed.' );
}
$db = wfGetDB( DB_SLAVE );
*/
protected function arrayWrap( array $elements ) {
return array_map(
- function( $element ) {
+ function ( $element ) {
return array( $element );
},
$elements
* @param String $actual HTML on oneline
* @param String $msg Optional message
*/
- protected function assertHTMLEquals( $expected, $actual, $msg='' ) {
+ protected function assertHTMLEquals( $expected, $actual, $msg = '' ) {
$expected = str_replace( '>', ">\n", $expected );
- $actual = str_replace( '>', ">\n", $actual );
+ $actual = str_replace( '>', ">\n", $actual );
$this->assertEquals( $expected, $actual, $msg );
}
protected function objectAssociativeSort( array &$array ) {
uasort(
$array,
- function( $a, $b ) {
+ function ( $a, $b ) {
return serialize( $a ) > serialize( $b ) ? 1 : -1;
}
);
protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
if ( $actual === $value ) {
$this->assertTrue( true, $message );
- }
- else {
+ } else {
$this->assertType( $type, $actual, $message );
}
}
protected function assertType( $type, $actual, $message = '' ) {
if ( class_exists( $type ) || interface_exists( $type ) ) {
$this->assertInstanceOf( $type, $actual, $message );
- }
- else {
+ } else {
$this->assertInternalType( $type, $actual, $message );
}
}
$namespaces = array_diff( $namespaces, array(
NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER // don't mess with magic namespaces
- ));
+ ) );
$talk = array_filter( $namespaces, function ( $ns ) {
return MWNamespace::isTalk( $ns );
// check default content model of each namespace
foreach ( $namespaces as $ns ) {
if ( !isset( $wgNamespaceContentModels[$ns] ) ||
- $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT ) {
+ $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT
+ ) {
$wikitextNS = $ns;
return $wikitextNS;
$haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
wfRestoreWarnings();
- if( !$haveDiff3 ) {
+ if ( !$haveDiff3 ) {
$this->markTestSkipped( "Skip test, since diff3 is not configured" );
}
}
protected function checkHasGzip() {
static $haveGzip;
- if( $haveGzip === null ) {
+ if ( $haveGzip === null ) {
$retval = null;
wfShellExec( 'gzip -V', $retval );
- $haveGzip = ($retval === 0);
+ $haveGzip = ( $retval === 0 );
}
- if( !$haveGzip ) {
+ if ( !$haveGzip ) {
$this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
}
*/
protected function checkPHPExtension( $extName ) {
$loaded = extension_loaded( $extName );
- if( ! $loaded ) {
+ if ( !$loaded ) {
$this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
}
return $loaded;
try {
call_user_func( $code );
- }
- catch ( Exception $pokemons ) {
+ } catch ( Exception $pokemons ) {
// Gotta Catch 'Em All!
}