Skip to content

Commit

Permalink
Make dataProviders static in lib, client, view, rest-api
Browse files Browse the repository at this point in the history
non-static dataProvider functions are deprecated as of PHPUnit 10.
Most of `repo` was covered in prior commits. With the exception of
a few remaining files that are entangled with other repos, this covers:
  - repo/rest-api
  - lib
  - client
  - view

Bug: T337154
Change-Id: I3be5623ebacc976c941cdee25992233b3846e3a4
  • Loading branch information
yerdua authored and WMDE bot committed Nov 25, 2024
1 parent 4064f97 commit b83b175
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 166 deletions.
38 changes: 19 additions & 19 deletions tests/unit/ByPropertyIdArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ByPropertyIdArrayTest extends \PHPUnit\Framework\TestCase {
public function testGivenNull_constructorAssumesEmptyArray() {
$indexedArray = new ByPropertyIdArray( null );

$this->assertSame( 0, $indexedArray->count() );
self::assertSame( 0, $indexedArray->count() );
}

public function testGivenNonTraversableObject_constructorDoesNotCastObjectToArray() {
Expand All @@ -59,7 +59,7 @@ public function testArrayObjectNotConstructedFromObject() {
// constructed from an object." This test makes sure it was not constructed from an object.
$byPropertyIdArray->append( $statement2 );

$this->assertCount( 2, $byPropertyIdArray );
self::assertCount( 2, $byPropertyIdArray );
}

/**
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testGetIds( array $objects ) {

$indexedArray->buildIndex();

$this->assertEquals(
self::assertEquals(
array_values( $expected ),
array_values( $indexedArray->getPropertyIds() )
);
Expand Down Expand Up @@ -170,11 +170,11 @@ public function testGetById( array $objects ) {
foreach ( $ids as $id ) {
foreach ( $indexedArray->getByPropertyId( $id ) as $obtainedObject ) {
$allObtainedObjects[] = $obtainedObject;
$this->assertEquals( $id, $obtainedObject->getPropertyId() );
self::assertEquals( $id, $obtainedObject->getPropertyId() );
}
}

$this->assertEquals(
self::assertEquals(
array_values( $objects ),
array_values( $allObtainedObjects )
);
Expand All @@ -194,15 +194,15 @@ public function testRemoveObject( array $objects ) {
$removeObject->invokeArgs( $indexedArray, [ $objects[0] ] );
$removeObject->invokeArgs( $indexedArray, [ $objects[$lastIndex] ] );

$this->assertNotContains(
self::assertNotContains(
$objects[0], $indexedArray->getByPropertyId( $objects[0]->getPropertyId() )
);

$this->assertNotContains( $objects[$lastIndex],
self::assertNotContains( $objects[$lastIndex],
$indexedArray->getByPropertyId( $objects[1]->getPropertyId() ) );

$this->assertNotContains( $objects[0], $indexedArray->toFlatArray() );
$this->assertNotContains( $objects[$lastIndex], $indexedArray->toFlatArray() );
self::assertNotContains( $objects[0], $indexedArray->toFlatArray() );
self::assertNotContains( $objects[$lastIndex], $indexedArray->toFlatArray() );
}

public function testGetByNotSetIdThrowsException() {
Expand Down Expand Up @@ -244,7 +244,7 @@ public function testGetFlatArrayIndexOfObject( array $objects ) {
$indicesDestination[$indexedArray->getFlatArrayIndexOfObject( $object )] = $object;
}

$this->assertEquals( $indicesSource, $indicesDestination );
self::assertEquals( $indicesSource, $indicesDestination );
}

/**
Expand All @@ -254,11 +254,11 @@ public function testToFlatArray( array $objects ) {
$indexedArray = new ByPropertyIdArray( $objects );
$indexedArray->buildIndex();

$this->assertEquals( $objects, $indexedArray->toFlatArray() );
self::assertEquals( $objects, $indexedArray->toFlatArray() );
}

public function moveProvider() {
$c = $this->statementsProvider();
public static function moveProvider() {
$c = self::statementsProvider();
$argLists = [];

$argLists[] = [ $c, $c[0], 0, $c ];
Expand Down Expand Up @@ -333,11 +333,11 @@ public function testMoveObjectToIndex(
$reindexedArray[] = $o;
}

$this->assertEquals( $objectsDestination, $reindexedArray );
self::assertEquals( $objectsDestination, $reindexedArray );
}

public function testMoveThrowingOutOfBoundsExceptionIfObjectNotPresent() {
$statements = $this->statementsProvider();
$statements = self::statementsProvider();
$indexedArray = new ByPropertyIdArray( $statements );
$indexedArray->buildIndex();

Expand All @@ -350,7 +350,7 @@ public function testMoveThrowingOutOfBoundsExceptionIfObjectNotPresent() {
}

public function testMoveThrowingOutOfBoundsExceptionOnInvalidIndex() {
$statements = $this->statementsProvider();
$statements = self::statementsProvider();
$indexedArray = new ByPropertyIdArray( $statements );
$indexedArray->buildIndex();

Expand All @@ -359,8 +359,8 @@ public function testMoveThrowingOutOfBoundsExceptionOnInvalidIndex() {
$indexedArray->moveObjectToIndex( $statements[0], 9999 );
}

public function addProvider() {
$c = $this->statementsProvider();
public static function addProvider() {
$c = self::statementsProvider();

$argLists = [];

Expand Down Expand Up @@ -404,7 +404,7 @@ public function testAddObjectAtIndex(

$indexedArray->addObjectAtIndex( $object, $index );

$this->assertEquals( $objectsDestination, $indexedArray->toFlatArray() );
self::assertEquals( $objectsDestination, $indexedArray->toFlatArray() );
}

}
50 changes: 25 additions & 25 deletions tests/unit/Entity/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class ItemTest extends \PHPUnit\Framework\TestCase {

private function getNewEmpty() {
private static function getNewEmpty() {
return new Item();
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public function testItemWithStuffIsNotEmpty() {
$this->assertFalse( $item->isEmpty() );

$item = new Item();
$item->getStatements()->addStatement( $this->newStatement() );
$item->getStatements()->addStatement( self::newStatement() );
$this->assertFalse( $item->isEmpty() );
}

Expand All @@ -198,7 +198,7 @@ public function testItemWithSitelinksHasSitelinks() {
$this->assertFalse( $item->getSiteLinkList()->isEmpty() );
}

private function newStatement() {
private static function newStatement() {
$statement = new Statement( new PropertyNoValueSnak( 42 ) );
$statement->setGuid( 'kittens' );
return $statement;
Expand Down Expand Up @@ -270,7 +270,7 @@ public function testEquals( Item $firstItem, Item $secondItem ) {
/**
* @return Item
*/
private function getBaseItem() {
private static function getBaseItem() {
$item = new Item( new ItemId( 'Q42' ) );
$item->setLabel( 'en', 'Same' );
$item->setDescription( 'en', 'Same' );
Expand All @@ -281,25 +281,25 @@ private function getBaseItem() {
return $item;
}

public function notEqualsProvider() {
$differentLabel = $this->getBaseItem();
public static function notEqualsProvider() {
$differentLabel = self::getBaseItem();
$differentLabel->setLabel( 'en', 'Different' );

$differentDescription = $this->getBaseItem();
$differentDescription = self::getBaseItem();
$differentDescription->setDescription( 'en', 'Different' );

$differentAlias = $this->getBaseItem();
$differentAlias = self::getBaseItem();
$differentAlias->setAliases( 'en', [ 'Different' ] );

$differentSiteLink = $this->getBaseItem();
$differentSiteLink = self::getBaseItem();
$differentSiteLink->getSiteLinkList()->removeLinkWithSiteId( 'enwiki' );
$differentSiteLink->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Different' );

$differentStatement = $this->getBaseItem();
$differentStatement = self::getBaseItem();
$differentStatement->setStatements( new StatementList() );
$differentStatement->getStatements()->addNewStatement( new PropertyNoValueSnak( 24 ) );

$item = $this->getBaseItem();
$item = self::getBaseItem();

return [
'empty' => [ $item, new Item() ],
Expand Down Expand Up @@ -401,7 +401,7 @@ public static function labelProvider() {
* @param string $moarText
*/
public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there' ) {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$entity->setLabel( $languageCode, $labelText );

Expand All @@ -419,7 +419,7 @@ public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there'
* @param string $moarText
*/
public function testSetDescription( $languageCode, $description, $moarText = 'ohi there' ) {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$entity->setDescription( $languageCode, $description );

Expand Down Expand Up @@ -459,7 +459,7 @@ public static function aliasesProvider() {
* @dataProvider aliasesProvider
*/
public function testSetAliases( array $aliasesLists ) {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

foreach ( $aliasesLists as $langCode => $aliasesList ) {
foreach ( $aliasesList as $aliases ) {
Expand Down Expand Up @@ -487,11 +487,11 @@ public function testSetEmptyAlias() {
$this->assertFalse( $item->getAliasGroups()->hasGroupForLanguage( 'en' ) );
}

public function instanceProvider() {
public static function instanceProvider() {
$entities = [];

// empty
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();
$entities[] = $entity;

// ID only
Expand All @@ -501,7 +501,7 @@ public function instanceProvider() {
$entities[] = $entity;

// with labels and stuff
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();
$entity->setAliases( 'en', [ 'o', 'noez' ] );
$entity->setLabel( 'de', 'spam' );
$entity->setDescription( 'en', 'foo bar baz' );
Expand Down Expand Up @@ -565,7 +565,7 @@ public function testSerialize( Item $entity ) {
}

public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$this->assertEquals(
new Fingerprint(),
Expand All @@ -574,7 +574,7 @@ public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() {
}

public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels() {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$entity->setLabel( 'en', 'foo' );
$entity->setLabel( 'de', 'bar' );
Expand All @@ -591,7 +591,7 @@ public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels(
}

public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$entity->setLabel( 'en', 'foo' );
$entity->setDescription( 'en', 'foo bar' );
Expand All @@ -614,14 +614,14 @@ public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms()
}

public function testGivenEmptyFingerprint_noTermsAreSet() {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();
$entity->setFingerprint( new Fingerprint() );

$this->assertTrue( $entity->getFingerprint()->isEmpty() );
}

public function testGivenEmptyFingerprint_existingTermsAreRemoved() {
$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();

$entity->setLabel( 'en', 'foo' );
$entity->setDescription( 'en', 'foo bar' );
Expand All @@ -645,7 +645,7 @@ public function testWhenSettingFingerprint_getFingerprintReturnsIt() {
] )
);

$entity = $this->getNewEmpty();
$entity = self::getNewEmpty();
$entity->setFingerprint( $fingerprint );
$newFingerprint = $entity->getFingerprint();

Expand Down Expand Up @@ -727,7 +727,7 @@ public function testClear( Item $item ) {
$this->assertTrue( $item->isEmpty(), 'cleared Item should be empty' );
}

public function clearableProvider() {
public static function clearableProvider() {
return [
'empty' => [ new Item( new ItemId( 'Q23' ) ) ],
'with fingerprint' => [
Expand All @@ -748,7 +748,7 @@ public function clearableProvider() {
new ItemId( 'Q321' ),
null,
null,
new StatementList( $this->newStatement() )
new StatementList( self::newStatement() )
),
],
];
Expand Down
Loading

0 comments on commit b83b175

Please sign in to comment.