Skip to content

Commit

Permalink
Merge "Make phpunit dataProviders static, part 4"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 1, 2024
2 parents 00de17c + e521eee commit 9ad1216
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testRun_noHooksRegisteredGoodStatus() {
$this->assertStatusGood( $status );
}

public function runData() {
public static function runData() {
return [
'good existing item' => [
Status::newGood(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function testDoHtmlPageLinkRendererBegin_invalidContext( LinkRenderer $li
$this->assertEquals( [], $customAttribs );
}

public function overrideSpecialNewEntityLinkProvider(): iterable {
public static function overrideSpecialNewEntityLinkProvider(): iterable {
$entityContentFactory = WikibaseRepo::getEntityContentFactory();
$namespaceLookup = $this->getEntityNamespaceLookup();
$namespaceLookup = self::getEntityNamespaceLookup();

foreach ( $entityContentFactory->getEntityTypes() as $entityType ) {
$entityHandler = $entityContentFactory->getContentHandlerForType( $entityType );
Expand Down Expand Up @@ -113,8 +113,8 @@ public function testDoHtmlPageLinkRendererBegin_overrideSpecialNewEntityLink(
$this->assertStringContainsString( $specialPageTitle->getFullText(), $html );
}

public function noOverrideSpecialNewEntityLinkProvider(): iterable {
$lookup = $this->getEntityNamespaceLookup();
public static function noOverrideSpecialNewEntityLinkProvider(): iterable {
$lookup = self::getEntityNamespaceLookup();
$itemNs = $lookup->getEntityNamespace( 'item' );
$propertyNs = $lookup->getEntityNamespace( 'property' );
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ protected function newTitle( string $id, bool $exists = true, int $namespace = N
return $title;
}

protected function newContext( string $title = 'Special:Recentchanges' ): RequestContext {
protected static function newContext( string $title = 'Special:Recentchanges' ): RequestContext {
return RequestContext::newExtraneousContext( Title::newFromTextThrow( $title ) );
}

protected function getLinkRenderer(): LinkRenderer {
protected static function getLinkRenderer(): LinkRenderer {
$linkRenderer = MediaWikiServices::getInstance()
->getLinkRendererFactory()->create( [ 'renderForComment' => true ] );
return $linkRenderer;
Expand Down Expand Up @@ -219,7 +219,7 @@ private function getTermLookup() {
return $termLookup;
}

final protected function getEntityNamespaceLookup() {
final protected static function getEntityNamespaceLookup() {
$entityNamespaces = [
'item' => 0,
'property' => 122,
Expand All @@ -240,19 +240,19 @@ private function getInterwikiLookup() {
return $lookup;
}

public function validLinkRendererAndContextProvider() {
$commentLinkRenderer = $this->getLinkRenderer();
public static function validLinkRendererAndContextProvider() {
$commentLinkRenderer = self::getLinkRenderer();
$nonCommentLinkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();

$specialPageContext = $this->newContext();
$specialPageContext = self::newContext();

$historyContext = $this->newContext( 'Foo' );
$historyContext = self::newContext( 'Foo' );
$historyContext->getRequest()->setVal( 'action', 'history' );

$diffContext = $this->newContext( 'Foo' );
$diffContext = self::newContext( 'Foo' );
$diffContext->getRequest()->setVal( 'diff', 123 );

$viewContext = $this->newContext( 'Foo' );
$viewContext = self::newContext( 'Foo' );

return [
'normal link, special page' => [ $nonCommentLinkRenderer, $specialPageContext ],
Expand All @@ -263,15 +263,15 @@ public function validLinkRendererAndContextProvider() {
];
}

public function invalidLinkRendererAndContextProvider() {
public static function invalidLinkRendererAndContextProvider() {
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();

$viewContext = $this->newContext( 'Foo' );
$viewContext = self::newContext( 'Foo' );

$diffContext = $this->newContext( 'Foo' );
$diffContext = self::newContext( 'Foo' );
$diffContext->getRequest()->setVal( 'diff', 123 );

$specialBadTitleContext = $this->newContext( 'Special:Badtitle' );
$specialBadTitleContext = self::newContext( 'Special:Badtitle' );

return [
'normal link, normal view' => [ $linkRenderer, $viewContext ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private function getEntityContentFactory() {
return $entityContentFactory;
}

public function getPlainSearches() {
public static function getPlainSearches() {
return [
"simple" => [
'Q1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function newLanguageFallbackChain() {
return $fallbackChain;
}

protected function newItem() {
protected static function newItem() {
$item = new Item( new ItemId( 'Q7799929' ) );

$item->setLabel( 'en', 'kitten item' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private function newInstance() {
* @param string $string
* @param int $propertyId
*/
private function addStatement( StatementList $statements, $string, $propertyId = 1 ) {
private static function addStatement( StatementList $statements, $string, $propertyId = 1 ) {
$statements->addNewStatement(
new PropertyValueSnak( $propertyId, new StringValue( $string ) )
);
Expand Down Expand Up @@ -67,15 +67,15 @@ public function testUpdateParserOutput( StatementList $statements, array $expect
$this->assertSame( $expected, $actual );
}

public function externalLinksProvider() {
public static function externalLinksProvider() {
$set1 = new StatementList();
$this->addStatement( $set1, 'http://1.de' );
$this->addStatement( $set1, '' );
$this->addStatement( $set1, 'no url property', 2 );
self::addStatement( $set1, 'http://1.de' );
self::addStatement( $set1, '' );
self::addStatement( $set1, 'no url property', 2 );

$set2 = new StatementList();
$this->addStatement( $set2, 'http://2a.de' );
$this->addStatement( $set2, 'http://2b.de' );
self::addStatement( $set2, 'http://2a.de' );
self::addStatement( $set2, 'http://2b.de' );

return [
[ new StatementList(), [] ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ protected function setUp(): void {
$this->entityViewFactory = $this->mockEntityViewFactory( false );
}

public function provideTestGetParserOutput() {
public static function provideTestGetParserOutput() {
return [
[
$this->newItem(),
self::newItem(),
'kitten item',
[ 'http://an.url.com', 'https://another.url.org' ],
[ 'File:This_is_a_file.pdf', 'File:Selfie.jpg' ],
Expand Down
78 changes: 39 additions & 39 deletions repo/tests/phpunit/includes/ParserOutput/GeoDataDataUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
class GeoDataDataUpdaterTest extends MediaWikiIntegrationTestCase {

private function willSkipTests() {
private static function willSkipTests() {
return !ExtensionRegistry::getInstance()->isLoaded( 'GeoData' );
}

Expand Down Expand Up @@ -63,13 +63,13 @@ public function testProcessStatement( array $expected, array $statements, $messa
$this->assertEquals( $expected, $updater->coordinates, $message );
}

public function processStatementProvider() {
if ( $this->willSkipTests() ) {
public static function processStatementProvider() {
if ( self::willSkipTests() ) {
return [ [ [], [], 'dummy test will be skipped' ] ];
}

$statements = $this->getStatements();
$coords = $this->getCoords();
$statements = self::getStatements();
$coords = self::getCoords();

return [
[
Expand Down Expand Up @@ -267,90 +267,90 @@ private function newGeoDataDataUpdater( array $preferredProperties ) {
);
}

private function getStatements() {
private static function getStatements() {
$statements = [];

$statements['P42-string'] = $this->newStatement(
$statements['P42-string'] = self::newStatement(
new NumericPropertyId( 'P42' ),
new StringValue( 'kittens!' )
);

$statements['P625-geo'] = $this->newStatement(
$statements['P625-geo'] = self::newStatement(
new NumericPropertyId( 'P625' ),
$this->newGlobeCoordinateValue( 19.7, 306.8, 'Q111' )
self::newGlobeCoordinateValue( 19.7, 306.8, 'Q111' )
);

$statements['P10-geo-A'] = $this->newStatement(
$statements['P10-geo-A'] = self::newStatement(
new NumericPropertyId( 'P10' ),
$this->newGlobeCoordinateValue( 40.748433, -73.985655 )
self::newGlobeCoordinateValue( 40.748433, -73.985655 )
);

$statements['P10-geo-B'] = $this->newStatement(
$statements['P10-geo-B'] = self::newStatement(
new NumericPropertyId( 'P10' ),
$this->newGlobeCoordinateValue( 44.264464, 52.643666 )
self::newGlobeCoordinateValue( 44.264464, 52.643666 )
);

$statements['P10-geo-preferred-A'] = $this->newStatementWithRank(
$statements['P10-geo-preferred-A'] = self::newStatementWithRank(
new NumericPropertyId( 'P10' ),
$this->newGlobeCoordinateValue( 50.02440, 41.50202 ),
self::newGlobeCoordinateValue( 50.02440, 41.50202 ),
Statement::RANK_PREFERRED
);

$statements['P10-geo-preferred-B'] = $this->newStatementWithRank(
$statements['P10-geo-preferred-B'] = self::newStatementWithRank(
new NumericPropertyId( 'P10' ),
$this->newGlobeCoordinateValue( 70.0144, 30.0015 ),
self::newGlobeCoordinateValue( 70.0144, 30.0015 ),
Statement::RANK_PREFERRED
);

$statements['P9000-geo-A'] = $this->newStatement(
$statements['P9000-geo-A'] = self::newStatement(
new NumericPropertyId( 'P9000' ),
$this->newGlobeCoordinateValue( 33.643664, 20.464222 )
self::newGlobeCoordinateValue( 33.643664, 20.464222 )
);

$statements['P9000-geo-B'] = $this->newStatementWithQualifier(
$statements['P9000-geo-B'] = self::newStatementWithQualifier(
new NumericPropertyId( 'P9000' ),
$this->newGlobeCoordinateValue( 11.1234, 12.5678 ),
self::newGlobeCoordinateValue( 11.1234, 12.5678 ),
new SnakList( [
new PropertyValueSnak(
new NumericPropertyId( 'P625' ),
$this->newGlobeCoordinateValue( 30.0987, 20.1234 )
self::newGlobeCoordinateValue( 30.0987, 20.1234 )
),
] )
);

$statements['P9000-geo-preferred'] = $this->newStatementWithRank(
$statements['P9000-geo-preferred'] = self::newStatementWithRank(
new NumericPropertyId( 'P9000' ),
$this->newGlobeCoordinateValue( 77.7777, 33.3333 ),
self::newGlobeCoordinateValue( 77.7777, 33.3333 ),
Statement::RANK_PREFERRED
);

$statements['P17-geo-deprecated'] = $this->newStatementWithRank(
$statements['P17-geo-deprecated'] = self::newStatementWithRank(
new NumericPropertyId( 'P17' ),
$this->newGlobeCoordinateValue( 10.0234, 11.52352 ),
self::newGlobeCoordinateValue( 10.0234, 11.52352 ),
Statement::RANK_DEPRECATED
);

$statements['P20-some-value'] = $this->newStatement( new NumericPropertyId( 'P20' ) );
$statements['P20-some-value'] = self::newStatement( new NumericPropertyId( 'P20' ) );

$statements['P10-mismatch'] = $this->newStatement(
$statements['P10-mismatch'] = self::newStatement(
new NumericPropertyId( 'P10' ),
new StringValue( 'omg! wrong value type' )
);

$statements['P404-unknown-property'] = $this->newStatement(
$statements['P404-unknown-property'] = self::newStatement(
new NumericPropertyId( 'P404' ),
$this->newGlobeCoordinateValue( 40.733643, -72.352153 )
self::newGlobeCoordinateValue( 40.733643, -72.352153 )
);

$statements['P9002-unknown-globe'] = $this->newStatement(
$statements['P9002-unknown-globe'] = self::newStatement(
new NumericPropertyId( 'P9002' ),
$this->newGlobeCoordinateValue( 9.017, 14.0987, 'Q147' )
self::newGlobeCoordinateValue( 9.017, 14.0987, 'Q147' )
);

return $statements;
}

private function getCoords() {
private static function getCoords() {
return [
'P625-geo' => new Coord( 19.7, 306.8, 'mars' ),
'P10-geo-A' => new Coord( 40.748433, -73.985655 ),
Expand All @@ -363,7 +363,7 @@ private function getCoords() {
];
}

private function newStatement( NumericPropertyId $propertyId, DataValue $dataValue = null ) {
private static function newStatement( NumericPropertyId $propertyId, DataValue $dataValue = null ) {
$guidGenerator = new GuidGenerator();

if ( $dataValue === null ) {
Expand All @@ -377,29 +377,29 @@ private function newStatement( NumericPropertyId $propertyId, DataValue $dataVal
return new Statement( $snak, null, null, $guid );
}

private function newStatementWithRank(
private static function newStatementWithRank(
NumericPropertyId $propertyId,
DataValue $dataValue,
$rank
) {
$rankedStatement = $this->newStatement( $propertyId, $dataValue );
$rankedStatement = self::newStatement( $propertyId, $dataValue );
$rankedStatement->setRank( $rank );

return $rankedStatement;
}

private function newStatementWithQualifier(
private static function newStatementWithQualifier(
NumericPropertyId $propertyId,
DataValue $dataValue,
SnakList $qualifiers
) {
$statement = $this->newStatement( $propertyId, $dataValue );
$statement = self::newStatement( $propertyId, $dataValue );
$statement->setQualifiers( $qualifiers );

return $statement;
}

private function newGlobeCoordinateValue( $lat, $lon, $globeId = 'Q2' ) {
private static function newGlobeCoordinateValue( $lat, $lon, $globeId = 'Q2' ) {
$latLongValue = new LatLongValue( $lat, $lon );

// default globe is 'Q2' (earth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function newInstance() {
* @param string $string
* @param int $propertyId
*/
private function addStatement( StatementList $statements, $string, $propertyId = 1 ) {
private static function addStatement( StatementList $statements, $string, $propertyId = 1 ) {
$statements->addNewStatement(
new PropertyValueSnak( $propertyId, new StringValue( $string ) )
);
Expand All @@ -81,19 +81,19 @@ public function testUpdateParserOutput(
$this->assertSame( $expectedFileSearchOptions, $parserOutput->getFileSearchOptions() );
}

public function imageLinksProvider() {
public static function imageLinksProvider() {
$set1 = new StatementList();
$this->addStatement( $set1, '1.jpg' );
$this->addStatement( $set1, '' );
$this->addStatement( $set1, 'no image property', 2 );
self::addStatement( $set1, '1.jpg' );
self::addStatement( $set1, '' );
self::addStatement( $set1, 'no image property', 2 );

$set2 = new StatementList();
$this->addStatement( $set2, '2a.jpg' );
$this->addStatement( $set2, '2b.jpg' );
self::addStatement( $set2, '2a.jpg' );
self::addStatement( $set2, '2b.jpg' );

$set3 = new StatementList();
$this->addStatement( $set3, '2a.jpg' );
$this->addStatement( $set3, 'Exists.png' );
self::addStatement( $set3, '2a.jpg' );
self::addStatement( $set3, 'Exists.png' );

return [
[ new StatementList(), [], [] ],
Expand Down
Loading

0 comments on commit 9ad1216

Please sign in to comment.