X-Git-Url: https://git.heureux-cyclage.org/index.php?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCase.php;h=51fbff1190a7505bdf0883a9b44f9a72383edf2d;hb=27d83878c01af1981a5ab1cf8fa143722623f6da;hp=dfc58816a1d4e5047bc9c4714195f437ed4db119;hpb=09870fb7770d45117860972b7d63e03f957c251c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index dfc58816a1..51fbff1190 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -81,17 +81,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $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 @@ -116,7 +116,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { parent::run( $result ); wfProfileOut( $logName ); - if( $needsResetDB ) { + if ( $needsResetDB ) { wfProfileIn( $logName . ' (reset-db)' ); $this->resetDB(); wfProfileOut( $logName . ' (reset-db)' ); @@ -128,7 +128,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * * 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 ) . '_' ); @@ -142,7 +142,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * 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/. @@ -188,7 +188,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( $this->needsDB() && $this->db ) { // Clean up open transactions - while( $this->db->trxLevel() > 0 ) { + while ( $this->db->trxLevel() > 0 ) { $this->db->rollback(); } @@ -213,7 +213,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( $this->needsDB() && $this->db ) { // Clean up open transactions - while( $this->db->trxLevel() > 0 ) { + while ( $this->db->trxLevel() > 0 ) { $this->db->rollback(); } @@ -276,7 +276,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function setMwGlobals( $pairs, $value = null ) { // Normalize (string, value) to an array - if( is_string( $pairs ) ) { + if ( is_string( $pairs ) ) { $pairs = array( $pairs => $value ); } @@ -356,8 +356,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { # 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 @@ -471,20 +471,24 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * 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__ ); } } @@ -500,9 +504,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { ); 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 ) ); @@ -543,14 +547,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } 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]; } @@ -595,7 +599,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 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 ); @@ -634,7 +638,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ protected function arrayWrap( array $elements ) { return array_map( - function( $element ) { + function ( $element ) { return array( $element ); }, $elements @@ -682,9 +686,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * @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 ); } @@ -699,7 +703,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function objectAssociativeSort( array &$array ) { uasort( $array, - function( $a, $b ) { + function ( $a, $b ) { return serialize( $a ) > serialize( $b ) ? 1 : -1; } ); @@ -742,8 +746,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) { if ( $actual === $value ) { $this->assertTrue( true, $message ); - } - else { + } else { $this->assertType( $type, $actual, $message ); } } @@ -762,8 +765,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 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 ); } } @@ -816,7 +818,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $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 ); @@ -829,7 +831,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { // 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; @@ -857,7 +860,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 ); wfRestoreWarnings(); - if( !$haveDiff3 ) { + if ( !$haveDiff3 ) { $this->markTestSkipped( "Skip test, since diff3 is not configured" ); } } @@ -875,13 +878,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 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" ); } @@ -896,7 +899,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ protected function checkPHPExtension( $extName ) { $loaded = extension_loaded( $extName ); - if( ! $loaded ) { + if ( !$loaded ) { $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." ); } return $loaded; @@ -917,8 +920,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { try { call_user_func( $code ); - } - catch ( Exception $pokemons ) { + } catch ( Exception $pokemons ) { // Gotta Catch 'Em All! }