Skip to content

Commit

Permalink
Merge "Make phpunit dataProviders static, part 3"
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 6093f8c + d214592 commit 00de17c
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function testInvalidConstruct( $guid, $snakHash ) {
new ChangeOpQualifierRemove( $guid, $snakHash );
}

public function changeOpRemoveProvider() {
public static function changeOpRemoveProvider() {
$snak = new PropertyValueSnak( 2754236, new StringValue( 'test' ) );
$args = [];

$item = $this->newItemWithClaim( 'q345', $snak );
$item = self::newItemWithClaim( 'q345', $snak );
$statements = $item->getStatements()->toArray();
/** @var Statement $statement */
$statement = reset( $statements );
Expand All @@ -69,7 +69,7 @@ public function testApplyRemoveQualifier( Item $item, ChangeOpQualifierRemove $c
$this->assertTrue( $changeOpResult->isEntityChanged() );
}

private function newItemWithClaim( $itemIdString, $snak ) {
private static function newItemWithClaim( $itemIdString, $snak ) {
$item = new Item( new ItemId( $itemIdString ) );

$item->getStatements()->addNewStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function testGetClaimGuid() {
$this->assertEquals( $guid, $changeop->getGuid() );
}

public function changeOpProvider() {
public static function changeOpProvider() {
$snak = new PropertyValueSnak( 2754236, new StringValue( 'test' ) );
$args = [];

$item = $this->newItemWithClaim( 'q345', $snak );
$item = self::newItemWithClaim( 'q345', $snak );
$statements = $item->getStatements()->toArray();
/** @var Statement $statement */
$statement = reset( $statements );
Expand All @@ -71,7 +71,7 @@ public function testApplyAddNewClaim( Item $item, ChangeOpRemoveStatement $chang
$this->assertTrue( $changeOpResult->isEntityChanged() );
}

private function newItemWithClaim( $itemIdString, $snak ) {
private static function newItemWithClaim( $itemIdString, $snak ) {
$item = new Item( new ItemId( $itemIdString ) );

$item->getStatements()->addNewStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function testInvalidConstruct( $guid, $rank ) {
new ChangeOpStatementRank( $guid, $rank );
}

public function changeOpProvider() {
public static function changeOpProvider() {
$snak = new PropertyValueSnak( 2754236, new StringValue( 'test' ) );
$args = [];

$item = $this->newItemWithClaim( 'q123', $snak );
$item = self::newItemWithClaim( 'q123', $snak );
$statements = $item->getStatements()->toArray();
/** @var Statement $statement */
$statement = reset( $statements );
Expand All @@ -76,7 +76,7 @@ public function testApplyStatementRank( Item $item, ChangeOpStatementRank $chang
$this->assertTrue( $changeOpResult->isEntityChanged() );
}

private function newItemWithClaim( $itemIdString, $mainSnak ) {
private static function newItemWithClaim( $itemIdString, $mainSnak ) {
$item = new Item( new ItemId( $itemIdString ) );

$item->getStatements()->addNewStatement(
Expand Down
14 changes: 7 additions & 7 deletions repo/tests/phpunit/includes/ChangeOp/ChangeOpStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public function testApply( StatementListProvider $entity, Statement $statement,
$this->assertTrue( $changeOpResult->isEntityChanged() );
}

public function provideTestApply() {
$item777 = $this->makeNewItemWithStatement( 'Q777', new PropertyNoValueSnak( 45 ) );
$item666 = $this->makeNewItemWithStatement( 'Q666', new PropertySomeValueSnak( 44 ) );
public static function provideTestApply() {
$item777 = self::makeNewItemWithStatement( 'Q777', new PropertyNoValueSnak( 45 ) );
$item666 = self::makeNewItemWithStatement( 'Q666', new PropertySomeValueSnak( 44 ) );

$item777Statements = $item777->getStatements()->toArray();
$item666Statements = $item666->getStatements()->toArray();
Expand Down Expand Up @@ -243,16 +243,16 @@ public function testApplyInvalidThrowsException( Item $item, Statement $statemen
$changeOpStatement->apply( $item );
}

public function applyInvalidThrowsExceptionProvider() {
public static function applyInvalidThrowsExceptionProvider() {
$itemEmpty = new Item( new ItemId( 'Q888' ) );
$noValueSnak = new PropertyNoValueSnak( new NumericPropertyId( 'P45' ) );
$someValueSnak = new PropertySomeValueSnak( new NumericPropertyId( 'P44' ) );

$statementWithInvalidGuid = new Statement( $noValueSnak );
$statementWithInvalidGuid->setGuid( 'Q0$' );

$item777 = $this->makeNewItemWithStatement( 'Q777', $noValueSnak );
$item666 = $this->makeNewItemWithStatement( 'Q666', $someValueSnak );
$item777 = self::makeNewItemWithStatement( 'Q777', $noValueSnak );
$item666 = self::makeNewItemWithStatement( 'Q666', $someValueSnak );

$item777Statements = $item777->getStatements()->toArray();
$item666Statements = $item666->getStatements()->toArray();
Expand Down Expand Up @@ -335,7 +335,7 @@ public function testInvalidApply( EntityDocument $item, ChangeOpStatement $chang
*
* @return Item
*/
private function makeNewItemWithStatement( $idString, Snak $mainSnak ) {
private static function makeNewItemWithStatement( $idString, Snak $mainSnak ) {
$id = new ItemId( $idString );

$statement = new Statement( $mainSnak );
Expand Down
14 changes: 7 additions & 7 deletions repo/tests/phpunit/includes/ChangeOp/ChangeOpsMergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public function testCanConstruct( Item $from, Item $to, array $ignoreConflicts )
$this->assertInstanceOf( ChangeOpsMerge::class, $changeOps );
}

public function provideValidConstruction() {
$from = $this->newItemWithId( 'Q111' );
$to = $this->newItemWithId( 'Q222' );
public static function provideValidConstruction() {
$from = self::newItemWithId( 'Q111' );
$to = self::newItemWithId( 'Q222' );
return [
[ $from, $to, [] ],
[ $from, $to, [ 'sitelink' ] ],
Expand All @@ -150,17 +150,17 @@ public function testInvalidIgnoreConflicts( Item $from, Item $to, array $ignoreC
);
}

public function provideInvalidConstruction() {
$from = $this->newItemWithId( 'Q111' );
$to = $this->newItemWithId( 'Q222' );
public static function provideInvalidConstruction() {
$from = self::newItemWithId( 'Q111' );
$to = self::newItemWithId( 'Q222' );
return [
[ $from, $to, [ 'label' ] ],
[ $from, $to, [ 'foo' ] ],
[ $from, $to, [ 'description', 'foo' ] ],
];
}

private function newItemWithId( $idString ) {
private static function newItemWithId( $idString ) {
return NewItem::withId( $idString )
->build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function getEntityWithExistingAliases() {
/**
* @return AliasesProvider|EntityDocument
*/
abstract protected function getEntity();
abstract protected static function getEntity();

/**
* @return ChangeOpDeserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getChangeOpDeserializer() {
return $this->newAliasesChangeOpDeserializer( $this->getTermChangeOpValidator() );
}

public function getEntity() {
public static function getEntity() {
return new Item();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function testGivenNewStatementChangeRequest_setsStatement( $changeRequest
);
}

public function setStatementProvider() {
public static function setStatementProvider() {
$property = new NumericPropertyId( 'P7' );
$statement = new Statement( new PropertyNoValueSnak( $property ) );
$statementSerialization = $this->getStatementSerializer()->serialize( $statement );
$entity = $this->getEntity();
$statementSerialization = self::getStatementSerializer()->serialize( $statement );
$entity = self::getEntity();

return [
'numeric index format' => [ [ 'claims' => [ $statementSerialization ] ], $entity, $property ],
Expand All @@ -57,11 +57,11 @@ public function testGivenRemoveChangeRequest_removesStatement( $changeRequest, E
$this->assertTrue( $entity->getStatements()->getByPropertyId( $property )->isEmpty() );
}

public function deleteStatementProvider() {
public static function deleteStatementProvider() {
$property = new NumericPropertyId( 'P7' );
$statement = new Statement( new PropertyNoValueSnak( $property ) );
$statement->setGuid( 'test-guid' );
$entity = $this->getEntity();
$entity = self::getEntity();
$entity->setStatements( new StatementList( $statement ) );

return [
Expand Down Expand Up @@ -99,13 +99,13 @@ public function testGivenEditChangeRequest_statementGetsChanged( $changeRequest,
);
}

public function editStatementProvider() {
public static function editStatementProvider() {
$property = new NumericPropertyId( 'P7' );
$statement = new Statement( new PropertyValueSnak( $property, new StringValue( 'foo' ) ) );
$entity = $this->getEntity();
$entity = self::getEntity();
$statement->setGuid( ( new GuidGenerator() )->newGuid( $entity->getId() ) );
$entity->setStatements( new StatementList( $statement ) );
$statementSerialization = $this->getStatementSerializer()->serialize( $statement );
$statementSerialization = self::getStatementSerializer()->serialize( $statement );
$statementSerialization['mainsnak']['datavalue']['value'] = 'bar';

return [
Expand All @@ -120,14 +120,14 @@ public function editStatementProvider() {
];
}

private function getStatementSerializer() {
private static function getStatementSerializer() {
return WikibaseRepo::getBaseDataModelSerializerFactory()->newStatementSerializer();
}

/**
* @return StatementListProvider|EntityDocument
*/
abstract protected function getEntity();
abstract protected static function getEntity();

/**
* @return ChangeOpDeserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getChangeOpDeserializer() {
return $this->newClaimsChangeOpDeserializer();
}

public function getEntity() {
public static function getEntity() {
return new Item( new ItemId( 'Q123' ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function getEntityWithEnDescription() {
/**
* @return DescriptionsProvider|EntityDocument
*/
abstract protected function getEntity();
abstract protected static function getEntity();

/**
* @return ChangeOpDeserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getChangeOpDeserializer() {
return $this->newDescriptionsChangeOpDeserializer( $this->getTermChangeOpValidator() );
}

public function getEntity() {
public static function getEntity() {
return new Item();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getChangeOpDeserializer() {
return $this->newItemChangeOpDeserializer();
}

public function getEntity() {
public static function getEntity() {
return new Item( new ItemId( 'Q23' ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function getEntityWithEnLabel() {
/**
* @return LabelsProvider|EntityDocument
*/
abstract protected function getEntity();
abstract protected static function getEntity();

/**
* @return ChangeOpDeserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getChangeOpDeserializer() {
return $this->newLabelsChangeOpDeserializer( $this->getTermChangeOpValidator() );
}

public function getEntity() {
public static function getEntity() {
return new Item();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PropertyChangeOpDeserializerTest extends \PHPUnit\Framework\TestCase {
use DescriptionsChangeOpDeserializationTester;
use LabelsChangeOpDeserializationTester;

public function getEntity() {
public static function getEntity() {
return new Property( new NumericPropertyId( 'P100' ), null, 'foo' );
}

Expand Down

0 comments on commit 00de17c

Please sign in to comment.