X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiTestCase.php;h=13d09ab4ee701ae48c706d650c9ed6604f7629fc;hp=10f5d41fb31b662e5c6a0483dacadbc432badd70;hb=b34260f3794623f34b069aa524c7189c9f8d8d8d;hpb=827c6bfa416d9d0de8cc8e22f9f3fa36d8129d44 diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 10f5d41fb3..13d09ab4ee 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -14,9 +14,10 @@ use Wikimedia\TestingAccessWrapper; /** * @since 1.18 */ -abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { +abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { use MediaWikiCoversValidator; + use PHPUnit4And6Compat; /** * The service locator created by prepareServices(). This service locator will @@ -260,20 +261,19 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * which we can't allow, as that would open a new connection for mysql. * Replace with a HashBag. They would not be going to persist anyway. */ - $hashCache = [ 'class' => 'HashBagOStuff', 'reportDupes' => false ]; + $hashCache = [ 'class' => HashBagOStuff::class, 'reportDupes' => false ]; $objectCaches = [ CACHE_DB => $hashCache, CACHE_ACCEL => $hashCache, CACHE_MEMCACHED => $hashCache, 'apc' => $hashCache, 'apcu' => $hashCache, - 'xcache' => $hashCache, 'wincache' => $hashCache, ] + $baseConfig->get( 'ObjectCaches' ); $defaultOverrides->set( 'ObjectCaches', $objectCaches ); $defaultOverrides->set( 'MainCacheType', CACHE_NONE ); - $defaultOverrides->set( 'JobTypeConf', [ 'default' => [ 'class' => 'JobQueueMemory' ] ] ); + $defaultOverrides->set( 'JobTypeConf', [ 'default' => [ 'class' => JobQueueMemory::class ] ] ); // Use a fast hash algorithm to hash passwords. $defaultOverrides->set( 'PasswordDefault', 'A' ); @@ -1080,6 +1080,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + SiteStatsInit::doPlaceholderInit(); + User::resetIdByNameCache(); // Make sysop user @@ -1393,9 +1395,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->ensureMockDatabaseConnection( $db ); foreach ( $tables as $tbl ) { - $tmp = self::$useTemporaryTables ? ' TEMPORARY ' : ''; $tbl = $db->tableName( $tbl ); - $db->query( "DROP $tmp TABLE IF EXISTS $tbl", __METHOD__ ); + $db->query( "DROP TABLE IF EXISTS $tbl", __METHOD__ ); if ( $tbl === 'page' ) { // Forget about the pages since they don't @@ -1475,44 +1476,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } - /** - * @since 1.18 - * - * @param string $func - * @param array $args - * - * @return mixed - * @throws MWException - */ - public function __call( $func, $args ) { - static $compatibility = [ - 'createMock' => 'createMock2', - ]; - - if ( isset( $compatibility[$func] ) ) { - return call_user_func_array( [ $this, $compatibility[$func] ], $args ); - } else { - throw new MWException( "Called non-existent $func method on " . static::class ); - } - } - - /** - * Return a test double for the specified class. - * - * @param string $originalClassName - * @return PHPUnit_Framework_MockObject_MockObject - * @throws Exception - */ - private function createMock2( $originalClassName ) { - return $this->getMockBuilder( $originalClassName ) - ->disableOriginalConstructor() - ->disableOriginalClone() - ->disableArgumentCloning() - // New in phpunit-mock-objects 3.2 (phpunit 5.4.0) - // ->disallowMockingUnknownTypes() - ->getMock(); - } - private static function unprefixTable( &$tableName, $ind, $prefix ) { $tableName = substr( $tableName, strlen( $prefix ) ); } @@ -1597,9 +1560,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * @param string $function */ public function hideDeprecated( $function ) { - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); wfDeprecated( $function ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); } /** @@ -1614,13 +1577,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * @param string|array $fields The columns to include in the result (and to sort by) * @param string|array $condition "where" condition(s) * @param array $expectedRows An array of arrays giving the expected rows. + * @param array $options Options for the query + * @param array $join_conds Join conditions for the query * * @throws MWException If this test cases's needsDB() method doesn't return true. * Test cases can use "@group Database" to enable database test support, * or list the tables under testing in $this->tablesUsed, or override the * needsDB() method. */ - protected function assertSelect( $table, $fields, $condition, array $expectedRows ) { + protected function assertSelect( + $table, $fields, $condition, array $expectedRows, array $options = [], array $join_conds = [] + ) { 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.' ); @@ -1628,7 +1595,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $db = wfGetDB( DB_REPLICA ); - $res = $db->select( $table, $fields, $condition, wfGetCaller(), [ 'ORDER BY' => $fields ] ); + $res = $db->select( + $table, + $fields, + $condition, + wfGetCaller(), + $options + [ 'ORDER BY' => $fields ], + $join_conds + ); $this->assertNotEmpty( $res, "query failed: " . $db->lastError() ); $i = 0; @@ -1882,9 +1856,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { # This check may also protect against code injection in # case of broken installations. - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); if ( !$haveDiff3 ) { $this->markTestSkipped( "Skip test, since diff3 is not configured" );