Merge "Clean up tests"

This commit is contained in:
jenkins-bot 2024-02-16 07:58:38 +00:00 committed by Gerrit Code Review
commit ba409888a1
25 changed files with 46 additions and 47 deletions

View file

@ -332,7 +332,7 @@ $wgAutoloadClasses += [
* should be considered deprecated and eventually removed.
*/
spl_autoload_register( static function ( $class ) {
if ( strpos( $class, 'PHPUnit_' ) !== 0 ) {
if ( !str_starts_with( $class, 'PHPUnit_' ) ) {
// Skip if it doesn't start with the old prefix
return;
}

View file

@ -611,7 +611,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
final protected function mediaWikiSetUp(): void {
$reflection = new ReflectionClass( $this );
// TODO: Eventually we should assert for test presence in /integration/
if ( strpos( $reflection->getFileName(), '/unit/' ) !== false ) {
if ( str_contains( $reflection->getFileName(), '/unit/' ) ) {
$this->fail( 'This integration test should not be in "tests/phpunit/unit" !' );
}
if ( $this->tablesUsed && !self::isTestInDatabaseGroup() ) {
@ -1849,7 +1849,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
$defaultArray = (array)$wgDefaultExternalStore;
$dbws = [];
foreach ( $defaultArray as $url ) {
if ( strpos( $url, 'DB://' ) === 0 ) {
if ( str_starts_with( $url, 'DB://' ) ) {
[ $proto, $cluster ] = explode( '://', $url, 2 );
// Avoid getPrimary() because setupDatabaseWithTestPrefix()
// requires Database instead of plain DBConnRef/IDatabase
@ -1873,7 +1873,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
$defaultArray = (array)$wgDefaultExternalStore;
foreach ( $defaultArray as $url ) {
if ( strpos( $url, 'DB://' ) === 0 ) {
if ( str_starts_with( $url, 'DB://' ) ) {
return true;
}
}

View file

@ -339,7 +339,7 @@ class ActionEntryPointTest extends MediaWikiIntegrationTestCase {
}
/**
* Test a post-send update can not set cookies (T191537).
* Test a post-send update cannot set cookies (T191537).
* @coversNothing
*/
public function testPostSendJobDoesNotSetCookie() {
@ -364,7 +364,7 @@ class ActionEntryPointTest extends MediaWikiIntegrationTestCase {
$mw->doPostOutputShutdown();
// restInPeace() might have been registered to a callback of
// register_postsend_function() and thus can not be triggered from
// register_postsend_function() and thus cannot be triggered from
// PHPUnit.
if ( $jobHasRun === false ) {
$mw->restInPeace();

View file

@ -152,7 +152,7 @@ class ApiWatchTest extends ApiTestCase {
// Previous tests may insert an invalid title
// like ":ApiEditPageTest testNonTextEdit", which
// can't be cleared.
if ( strpos( $item['title'], ':' ) === 0 ) {
if ( str_starts_with( $item['title'], ':' ) ) {
unset( $data[0]['query']['watchlist'][$index] );
}
}

View file

@ -61,8 +61,8 @@ abstract class ApiQueryContinueTestBase extends ApiQueryTestBase {
$request = array_merge( $params, $continue );
uksort( $request, static function ( $a, $b ) {
// put 'continue' params at the end - lazy method
$a = strpos( $a, 'continue' ) !== false ? 'zzz ' . $a : $a;
$b = strpos( $b, 'continue' ) !== false ? 'zzz ' . $b : $b;
$a = str_contains( $a, 'continue' ) ? 'zzz ' . $a : $a;
$b = str_contains( $b, 'continue' ) ? 'zzz ' . $b : $b;
return strcmp( $a, $b );
} );

View file

@ -432,7 +432,7 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
$expected = array_filter( $expected,
static function ( $info ) {
return strpos( $info['type'], 'mediawiki-' ) !== 0;
return !str_starts_with( $info['type'], 'mediawiki-' );
}
);

View file

@ -816,7 +816,7 @@ hello
// create page
$ns = $this->getDefaultWikitextNS();
$title = Title::makeTitle( NS_MAIN, 'EditPageTest_testAutoMerge', $ns );
$title = Title::makeTitle( $ns, 'EditPageTest_testAutoMerge' );
$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();
$page = $wikiPageFactory->newFromTitle( $title );

View file

@ -43,7 +43,7 @@ class MWHttpRequestTest extends PHPUnit\Framework\TestCase {
// commented these out in order to remove @group Broken
// @todo are these valid tests? if so, fix MWHttpRequest::isValidURI so it can handle them
// [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
// [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
// [ false, 'http://exam:ple.org/', 'hostname cannot use colons!' ],
# (:[0-9]+)? - port number
[ true, 'http://example.org:80/' ],

View file

@ -447,7 +447,7 @@ class LogFormatterTest extends MediaWikiLangTestCase {
* Third parties bots listen to those messages. They are clever enough
* to fetch the i18n messages from the wiki and then analyze the IRC feed
* to reverse engineer the $1, $2 messages.
* One thing bots can not detect is when MediaWiki change the meaning of
* One thing bots cannot detect is when MediaWiki change the meaning of
* a message like what happened when we deployed 1.19. $1 became the user
* performing the action which broke basically all bots around.
*

View file

@ -647,7 +647,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase {
}
/**
* Tests that a RevisionRecord with no ID can not be rendered if OPT_NO_CACHE is not set.
* Tests that a RevisionRecord with no ID cannot be rendered if OPT_NO_CACHE is not set.
*/
public function testFakeRevisionError() {
$access = $this->getParserOutputAccessNoCache();

View file

@ -508,7 +508,7 @@ class SearchEngineTest extends MediaWikiLangTestCase {
*/
public function testParseNamespacePrefix( array $params, $expected ) {
$this->setTemporaryHook( 'PrefixSearchExtractNamespace', static function ( &$namespaces, &$query ) {
if ( strpos( $query, 'hélp:' ) === 0 ) {
if ( str_starts_with( $query, 'hélp:' ) ) {
$namespaces = [ NS_HELP ];
$query = substr( $query, strlen( 'hélp:' ) );
}

View file

@ -40,10 +40,10 @@ class SessionManagerTest extends MediaWikiIntegrationTestCase {
]
] );
$this->logger = new \TestLogger( false, static function ( $m ) {
return ( strpos( $m, 'SessionBackend ' ) === 0
|| strpos( $m, 'SessionManager using store ' ) === 0
return ( str_starts_with( $m, 'SessionBackend ' )
|| str_starts_with( $m, 'SessionManager using store ' )
// These were added for T264793 and behave somewhat erratically, not worth testing
|| strpos( $m, 'Failed to load session, unpersisting' ) === 0
|| str_starts_with( $m, 'Failed to load session, unpersisting' )
|| preg_match( '/^(Persisting|Unpersisting) session (for|due to)/', $m )
) ? null : $m;
} );

View file

@ -51,7 +51,7 @@ class SkinMustacheTest extends MediaWikiIntegrationTestCase {
return;
} elseif ( is_array( $value ) ) {
$this->assertTrue(
strpos( $key, 'data-' ) === 0 || strpos( $key, 'array-' ) === 0,
str_starts_with( $key, 'data-' ) || str_starts_with( $key, 'array-' ),
"Template data that is an object should be associated with a key" .
" prefixed with `data-` or `array-` ($key)"
);
@ -69,20 +69,20 @@ class SkinMustacheTest extends MediaWikiIntegrationTestCase {
}
}
} elseif ( is_string( $value ) ) {
if ( strpos( $value, '<' ) !== false ) {
if ( str_contains( $value, '<' ) ) {
$this->assertTrue(
strpos( $key, 'html-' ) === 0 || $key === 'html',
str_starts_with( $key, 'html-' ) || $key === 'html',
"Template data containing HTML must be prefixed with `html-` ($key)"
);
}
} elseif ( is_bool( $value ) ) {
$this->assertTrue(
strpos( $key, 'is-' ) === 0 || strpos( $key, 'has-' ) === 0,
str_starts_with( $key, 'is-' ) || str_starts_with( $key, 'has-' ),
"Template data containing booleans must be prefixed with `is-` or `has-` ($key)"
);
} elseif ( is_numeric( $value ) ) {
$this->assertTrue(
strpos( $key, 'number-' ) === 0,
str_starts_with( $key, 'number-' ),
"Template data containing numbers must be prefixed with `number-` ($key)"
);
} else {

View file

@ -153,7 +153,7 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase
if ( $var instanceof IExpression ) {
$var = $var->toGeneralizedSql();
}
return ( is_array( $var ) || strpos( (string)$var, 'rc_timestamp ' ) === false );
return is_array( $var ) || !str_contains( (string)$var, 'rc_timestamp ' );
}
public function testRcNsFilter() {

View file

@ -23,7 +23,7 @@ class QueryAllSpecialPagesTest extends MediaWikiIntegrationTestCase {
*/
private $queryPages;
/** @var string[] List query pages that can not be tested automatically */
/** @var string[] List query pages that cannot be tested automatically */
protected $manualTest = [
SpecialLinkSearch::class
];
@ -60,12 +60,12 @@ class QueryAllSpecialPagesTest extends MediaWikiIntegrationTestCase {
// With MySQL, skips special pages reopening a temporary table
// See https://bugs.mysql.com/bug.php?id=10327
if (
$this->db->getType() == 'mysql' &&
strpos( $this->db->getSoftwareLink(), 'MySQL' ) &&
$this->db->getType() === 'mysql' &&
str_contains( $this->db->getSoftwareLink(), 'MySQL' ) &&
in_array( $page->getName(), $this->reopensTempTable )
) {
$this->markTestSkipped( "SQL query for page {$page->getName()} "
. "can not be tested on MySQL backend (it reopens a temporary table)" );
. "cannot be tested on MySQL backend (it reopens a temporary table)" );
continue;
}

View file

@ -262,7 +262,7 @@ class XmlTest extends MediaWikiIntegrationTestCase {
$this->assertEquals(
'<label for="id">name</label>',
Xml::label( 'name', 'id', [ 'generated' => true ] ),
'label() can not be given a generated attribute'
'label() cannot be given a generated attribute'
);
$this->assertEquals(
'<label for="id" class="nice">name</label>',

View file

@ -223,8 +223,8 @@ abstract class ExtensionJsonTestBase extends MediaWikiIntegrationTestCase {
public function testServicesSorted( array $services ): void {
$sortedServices = $services;
usort( $sortedServices, function ( $serviceA, $serviceB ) {
$isExtensionServiceA = strpos( $serviceA, $this->serviceNamePrefix ) === 0;
$isExtensionServiceB = strpos( $serviceB, $this->serviceNamePrefix ) === 0;
$isExtensionServiceA = str_starts_with( $serviceA, $this->serviceNamePrefix );
$isExtensionServiceB = str_starts_with( $serviceB, $this->serviceNamePrefix );
if ( $isExtensionServiceA !== $isExtensionServiceB ) {
return $isExtensionServiceA ? 1 : -1;
}

View file

@ -90,7 +90,7 @@ class AvailableRightsTest extends MediaWikiIntegrationTestCase {
}
/**
* Test, if for all rights an action- message exist,
* Test, if for all rights an action- message exists,
* which is used on Special:ListGroupRights as help text
* Extensions and core
*
@ -101,7 +101,7 @@ class AvailableRightsTest extends MediaWikiIntegrationTestCase {
}
/**
* Test, if for all rights a right- message exist,
* Test, if for all rights a right- message exists,
* which is used on Special:ListGroupRights as help text
* Extensions and core
*/
@ -120,8 +120,7 @@ class AvailableRightsTest extends MediaWikiIntegrationTestCase {
$messagesToCheck = [];
foreach ( $allMessageKeys as $message ) {
// === 0: must be at beginning of string (position 0)
if ( strpos( $message, $prefix ) === 0 ) {
if ( str_starts_with( $message, $prefix ) ) {
$messagesToCheck[] = substr( $message, strlen( $prefix ) );
}
}

View file

@ -53,10 +53,10 @@ abstract class BundleSizeTestBase extends MediaWikiIntegrationTestCase {
$projectName = $testCase['projectName'] ?? '';
$moduleName = $testCase['resourceModule'];
if ( is_string( $maxSize ) ) {
if ( strpos( $maxSize, 'KB' ) !== false || strpos( $maxSize, 'kB' ) !== false ) {
if ( str_contains( $maxSize, 'KB' ) || str_contains( $maxSize, 'kB' ) ) {
$maxSize = (float)str_replace( [ 'KB', 'kB', ' KB', ' kB' ], '', $maxSize );
$maxSize = $maxSize * 1024;
} elseif ( strpos( $maxSize, 'B' ) !== false ) {
} elseif ( str_contains( $maxSize, 'B' ) ) {
$maxSize = (float)str_replace( [ ' B', 'B' ], '', $maxSize );
}
}

View file

@ -107,7 +107,7 @@ class PHPUnitConfigTest extends PHPUnit\Framework\TestCase {
return true;
}
if ( strpos( "$dirB/", $dirA ) === 0 ) {
if ( str_starts_with( "$dirB/", $dirA ) ) {
return true;
}

View file

@ -106,7 +106,7 @@ class ParserTestTopLevelSuite extends TestSuite {
# Filter out .txt files
$files = ParserTestRunner::getParserTestFiles();
foreach ( $files as $extName => $parserTestFile ) {
$isCore = ( strpos( $parserTestFile, $mwTestDir ) === 0 );
$isCore = str_starts_with( $parserTestFile, $mwTestDir );
if ( $isCore && $wantsCore ) {
self::debug( "included core parser tests: $parserTestFile" );
@ -124,7 +124,7 @@ class ParserTestTopLevelSuite extends TestSuite {
$testList = [];
$counter = 0;
foreach ( $filesToTest as $extensionName => $fileName ) {
$isCore = ( strpos( $fileName, $mwTestDir ) === 0 );
$isCore = str_starts_with( $fileName, $mwTestDir );
if ( is_int( $extensionName ) ) {
// If there's no extension name because this is coming
// from the legacy global, then assume the next level directory

View file

@ -66,7 +66,7 @@ TEXT;
}
// Make sure our stack trace contains an array and an object passed to
// some function in the stacktrace. Else, we can not assert the trace
// some function in the stacktrace. Else, we cannot assert the trace
// redaction achieved its job.
$trace = $e->getTrace();
$hasObject = false;

View file

@ -10,7 +10,7 @@ class DebugInfoTraitTest extends \PHPUnit\Framework\TestCase {
public function setUp(): void {
if ( extension_loaded( 'xdebug' ) ) {
if ( version_compare( phpversion( 'xdebug' ), '3.0.0', '>=' ) ) {
if ( strpos( ini_get( 'xdebug.mode' ), 'develop' ) !== false ) {
if ( str_contains( ini_get( 'xdebug.mode' ), 'develop' ) ) {
$this->markTestSkipped( 'Can\'t run this test with xdebug.mode=develop. ' .
'Use xdebug.mode=coverage to do test coverage without overloading var_dump.' );
}

View file

@ -26,7 +26,7 @@ class MovePageTest extends MediaWikiUnitTestCase {
'authority' => $this->mockRegisteredUltimateAuthority(),
'good' => true,
];
yield 'can not move' => [
yield 'cannot move' => [
'authority' => $this->mockAnonAuthority( function (
string $permission,
PageIdentity $page,
@ -41,7 +41,7 @@ class MovePageTest extends MediaWikiUnitTestCase {
} ),
'good' => false,
];
yield 'can not edit old page' => [
yield 'cannot edit old page' => [
'authority' => $this->mockAnonAuthority( static function (
string $permission,
PageIdentity $page,
@ -55,7 +55,7 @@ class MovePageTest extends MediaWikiUnitTestCase {
} ),
'good' => false,
];
yield 'can not move-target' => [
yield 'cannot move-target' => [
'authority' => $this->mockAnonAuthority( function (
string $permission,
PageIdentity $page,
@ -70,7 +70,7 @@ class MovePageTest extends MediaWikiUnitTestCase {
} ),
'good' => false,
];
yield 'can not edit new page' => [
yield 'cannot edit new page' => [
'authority' => $this->mockAnonAuthority( static function (
string $permission,
PageIdentity $page,

View file

@ -344,7 +344,7 @@ class MaintenanceParametersTest extends TestCase {
private function findInLines( array $lines, $regex, $start = 0 ) {
for ( $i = $start; $i < count( $lines ); $i++ ) {
if ( strpos( $lines[ $i ], $regex ) !== false ) {
if ( str_contains( $lines[ $i ], $regex ) ) {
return $i;
}
}