From b83b17560bfa74f9c75e28b317eb76341306845f Mon Sep 17 00:00:00 2001 From: Audrey Penven Date: Mon, 18 Nov 2024 17:28:03 +0100 Subject: [PATCH] Make dataProviders static in lib, client, view, rest-api 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 --- tests/unit/ByPropertyIdArrayTest.php | 38 ++--- tests/unit/Entity/ItemTest.php | 50 +++---- tests/unit/Entity/PropertyTest.php | 58 ++++---- tests/unit/Statement/StatementGuidTest.php | 4 +- tests/unit/Statement/StatementListTest.php | 164 ++++++++++----------- tests/unit/Statement/StatementTest.php | 18 +-- 6 files changed, 166 insertions(+), 166 deletions(-) diff --git a/tests/unit/ByPropertyIdArrayTest.php b/tests/unit/ByPropertyIdArrayTest.php index 3e5ebf28..5dffd5fb 100644 --- a/tests/unit/ByPropertyIdArrayTest.php +++ b/tests/unit/ByPropertyIdArrayTest.php @@ -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() { @@ -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 ); } /** @@ -142,7 +142,7 @@ public function testGetIds( array $objects ) { $indexedArray->buildIndex(); - $this->assertEquals( + self::assertEquals( array_values( $expected ), array_values( $indexedArray->getPropertyIds() ) ); @@ -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 ) ); @@ -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() { @@ -244,7 +244,7 @@ public function testGetFlatArrayIndexOfObject( array $objects ) { $indicesDestination[$indexedArray->getFlatArrayIndexOfObject( $object )] = $object; } - $this->assertEquals( $indicesSource, $indicesDestination ); + self::assertEquals( $indicesSource, $indicesDestination ); } /** @@ -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 ]; @@ -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(); @@ -350,7 +350,7 @@ public function testMoveThrowingOutOfBoundsExceptionIfObjectNotPresent() { } public function testMoveThrowingOutOfBoundsExceptionOnInvalidIndex() { - $statements = $this->statementsProvider(); + $statements = self::statementsProvider(); $indexedArray = new ByPropertyIdArray( $statements ); $indexedArray->buildIndex(); @@ -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 = []; @@ -404,7 +404,7 @@ public function testAddObjectAtIndex( $indexedArray->addObjectAtIndex( $object, $index ); - $this->assertEquals( $objectsDestination, $indexedArray->toFlatArray() ); + self::assertEquals( $objectsDestination, $indexedArray->toFlatArray() ); } } diff --git a/tests/unit/Entity/ItemTest.php b/tests/unit/Entity/ItemTest.php index b93f9942..94813be5 100644 --- a/tests/unit/Entity/ItemTest.php +++ b/tests/unit/Entity/ItemTest.php @@ -30,7 +30,7 @@ */ class ItemTest extends \PHPUnit\Framework\TestCase { - private function getNewEmpty() { + private static function getNewEmpty() { return new Item(); } @@ -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() ); } @@ -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; @@ -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' ); @@ -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() ], @@ -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 ); @@ -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 ); @@ -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 ) { @@ -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 @@ -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' ); @@ -565,7 +565,7 @@ public function testSerialize( Item $entity ) { } public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() { - $entity = $this->getNewEmpty(); + $entity = self::getNewEmpty(); $this->assertEquals( new Fingerprint(), @@ -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' ); @@ -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' ); @@ -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' ); @@ -645,7 +645,7 @@ public function testWhenSettingFingerprint_getFingerprintReturnsIt() { ] ) ); - $entity = $this->getNewEmpty(); + $entity = self::getNewEmpty(); $entity->setFingerprint( $fingerprint ); $newFingerprint = $entity->getFingerprint(); @@ -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' => [ @@ -748,7 +748,7 @@ public function clearableProvider() { new ItemId( 'Q321' ), null, null, - new StatementList( $this->newStatement() ) + new StatementList( self::newStatement() ) ), ], ]; diff --git a/tests/unit/Entity/PropertyTest.php b/tests/unit/Entity/PropertyTest.php index c7cbc5ee..04579318 100644 --- a/tests/unit/Entity/PropertyTest.php +++ b/tests/unit/Entity/PropertyTest.php @@ -29,7 +29,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase { /** * @return Property */ - private function getNewEmpty() { + private static function getNewEmpty() { return Property::newFromType( 'string' ); } @@ -112,13 +112,13 @@ public function testGetStatementsReturnsEmptyListForEmptyProperty() { public function testSetAndGetStatements() { $property = Property::newFromType( 'string' ); - $statementList = $this->newNonEmptyStatementList(); + $statementList = self::newNonEmptyStatementList(); $property->setStatements( $statementList ); $this->assertEquals( $statementList, $property->getStatements() ); } - private function newNonEmptyStatementList() { + private static function newNonEmptyStatementList() { $statementList = new StatementList(); $statementList->addNewStatement( new PropertyNoValueSnak( 42 ) ); $statementList->addNewStatement( new PropertyNoValueSnak( 1337 ) ); @@ -126,12 +126,12 @@ private function newNonEmptyStatementList() { return $statementList; } - public function equalsProvider() { + public static function equalsProvider() { $firstProperty = Property::newFromType( 'string' ); - $firstProperty->setStatements( $this->newNonEmptyStatementList() ); + $firstProperty->setStatements( self::newNonEmptyStatementList() ); $secondProperty = Property::newFromType( 'string' ); - $secondProperty->setStatements( $this->newNonEmptyStatementList() ); + $secondProperty->setStatements( self::newNonEmptyStatementList() ); $secondPropertyWithId = $secondProperty->copy(); $secondPropertyWithId->setId( new NumericPropertyId( 'P42' ) ); @@ -155,32 +155,32 @@ public function testEquals( Property $firstProperty, Property $secondProperty ) $this->assertTrue( $secondProperty->equals( $firstProperty ) ); } - private function getBaseProperty() { + private static function getBaseProperty() { $property = Property::newFromType( 'string' ); $property->setId( new NumericPropertyId( 'P42' ) ); $property->setLabel( 'en', 'Same' ); $property->setDescription( 'en', 'Same' ); $property->setAliases( 'en', [ 'Same' ] ); - $property->setStatements( $this->newNonEmptyStatementList() ); + $property->setStatements( self::newNonEmptyStatementList() ); return $property; } - public function notEqualsProvider() { - $differentLabel = $this->getBaseProperty(); + public static function notEqualsProvider() { + $differentLabel = self::getBaseProperty(); $differentLabel->setLabel( 'en', 'Different' ); - $differentDescription = $this->getBaseProperty(); + $differentDescription = self::getBaseProperty(); $differentDescription->setDescription( 'en', 'Different' ); - $differentAlias = $this->getBaseProperty(); + $differentAlias = self::getBaseProperty(); $differentAlias->setAliases( 'en', [ 'Different' ] ); - $differentStatement = $this->getBaseProperty(); + $differentStatement = self::getBaseProperty(); $differentStatement->setStatements( new StatementList() ); - $property = $this->getBaseProperty(); + $property = self::getBaseProperty(); return [ 'empty' => [ $property, Property::newFromType( 'string' ) ], @@ -202,7 +202,7 @@ public function testNotEquals( Property $firstProperty, Property $secondProperty public function testPropertyWithStatementsIsNotEmpty() { $property = Property::newFromType( 'string' ); - $property->setStatements( $this->newNonEmptyStatementList() ); + $property->setStatements( self::newNonEmptyStatementList() ); $this->assertFalse( $property->isEmpty() ); } @@ -280,7 +280,7 @@ public static function labelProvider() { * @param string $moarText */ public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there' ) { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setLabel( $languageCode, $labelText ); @@ -298,7 +298,7 @@ public function testSetLabel( $languageCode, $labelText, $moarText = 'ohi there' * @param string $moarText */ public function testSetDescription( $languageCode, $description, $moarText = 'ohi there' ) { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setDescription( $languageCode, $description ); @@ -338,7 +338,7 @@ public static function aliasesProvider() { * @dataProvider aliasesProvider */ public function testSetAliases( array $aliasesLists ) { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); foreach ( $aliasesLists as $langCode => $aliasesList ) { foreach ( $aliasesList as $aliases ) { @@ -366,11 +366,11 @@ public function testSetEmptyAlias() { $this->assertFalse( $property->getAliasGroups()->hasGroupForLanguage( 'en' ) ); } - public function instanceProvider() { + public static function instanceProvider() { $entities = []; // empty - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entities[] = $entity; // ID only @@ -380,7 +380,7 @@ public function instanceProvider() { $entities[] = $entity; // with labels and stuff - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setAliases( 'en', [ 'o', 'noez' ] ); $entity->setLabel( 'de', 'spam' ); $entity->setDescription( 'en', 'foo bar baz' ); @@ -444,7 +444,7 @@ public function testSerialize( Property $entity ) { } public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $this->assertEquals( new Fingerprint(), @@ -453,7 +453,7 @@ public function testWhenNoStuffIsSet_getFingerprintReturnsEmptyFingerprint() { } public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels() { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setLabel( 'en', 'foo' ); $entity->setLabel( 'de', 'bar' ); @@ -470,7 +470,7 @@ public function testWhenLabelsAreSet_getFingerprintReturnsFingerprintWithLabels( } public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setLabel( 'en', 'foo' ); $entity->setDescription( 'en', 'foo bar' ); @@ -493,14 +493,14 @@ public function testWhenTermsAreSet_getFingerprintReturnsFingerprintWithTerms() } public function testGivenEmptyFingerprint_noTermsAreSet() { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setFingerprint( new Fingerprint() ); $this->assertTrue( $entity->getFingerprint()->isEmpty() ); } public function testGivenEmptyFingerprint_existingTermsAreRemoved() { - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setLabel( 'en', 'foo' ); $entity->setDescription( 'en', 'foo bar' ); @@ -524,7 +524,7 @@ public function testWhenSettingFingerprint_getFingerprintReturnsIt() { ] ) ); - $entity = $this->getNewEmpty(); + $entity = static::getNewEmpty(); $entity->setFingerprint( $fingerprint ); $newFingerprint = $entity->getFingerprint(); @@ -615,7 +615,7 @@ public function testClear( Property $property ) { $this->assertTrue( $property->isEmpty(), 'cleared Property should be empty' ); } - public function clearableProvider() { + public static function clearableProvider() { return [ 'empty' => [ new Property( new NumericPropertyId( 'P123' ), null, 'string' ), @@ -632,7 +632,7 @@ public function clearableProvider() { new NumericPropertyId( 'P234' ), null, 'wikibase-entityid', - $this->newNonEmptyStatementList() + self::newNonEmptyStatementList() ), ], ]; diff --git a/tests/unit/Statement/StatementGuidTest.php b/tests/unit/Statement/StatementGuidTest.php index 854dd3e4..0d8df77f 100644 --- a/tests/unit/Statement/StatementGuidTest.php +++ b/tests/unit/Statement/StatementGuidTest.php @@ -70,10 +70,10 @@ public static function provideValidConstructionData(): array { ]; } - public function provideStatementGuids(): array { + public static function provideStatementGuids(): array { $argLists = []; - foreach ( $this->provideValidConstructionData() as $data ) { + foreach ( self::provideValidConstructionData() as $data ) { $argLists[] = [ new StatementGuid( ...$data ) ]; } diff --git a/tests/unit/Statement/StatementListTest.php b/tests/unit/Statement/StatementListTest.php index 6b4a0193..b388392c 100644 --- a/tests/unit/Statement/StatementListTest.php +++ b/tests/unit/Statement/StatementListTest.php @@ -64,8 +64,8 @@ private function getStatement( * * @return Statement */ - private function getStatementWithSnak( string $propertyId, string $stringValue ): Statement { - $snak = $this->newSnak( $propertyId, $stringValue ); + private static function getStatementWithSnak( string $propertyId, string $stringValue ): Statement { + $snak = self::newSnak( $propertyId, $stringValue ); $statement = new Statement( $snak ); $statement->setGuid( sha1( $snak->getHash() ) ); return $statement; @@ -77,7 +77,7 @@ private function getStatementWithSnak( string $propertyId, string $stringValue ) * * @return Snak */ - private function newSnak( string $propertyId, string $stringValue ) { + private static function newSnak( string $propertyId, string $stringValue ) { return new PropertyValueSnak( new NumericPropertyId( $propertyId ), new StringValue( $stringValue ) @@ -138,19 +138,19 @@ public function testCanIterate() { public function testGetUniqueMainSnaksReturnsListWithoutDuplicates() { $list = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'foo' ), - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), - $this->getStatementWithSnak( 'P1', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'foo' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P1', 'bar' ) ); $this->assertEquals( [ - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), - $this->getStatementWithSnak( 'P1', 'bar' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P1', 'bar' ), ], array_values( $list->getWithUniqueMainSnaks()->toArray() ) ); @@ -158,20 +158,20 @@ public function testGetUniqueMainSnaksReturnsListWithoutDuplicates() { public function testGetAllSnaksReturnsAllSnaks() { $list = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'foo' ), - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), - $this->getStatementWithSnak( 'P1', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'foo' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P1', 'bar' ) ); $this->assertEquals( [ - $this->newSnak( 'P1', 'foo' ), - $this->newSnak( 'P2', 'foo' ), - $this->newSnak( 'P1', 'foo' ), - $this->newSnak( 'P2', 'bar' ), - $this->newSnak( 'P1', 'bar' ), + self::newSnak( 'P1', 'foo' ), + self::newSnak( 'P2', 'foo' ), + self::newSnak( 'P1', 'foo' ), + self::newSnak( 'P2', 'bar' ), + self::newSnak( 'P1', 'bar' ), ], $list->getAllSnaks() ); @@ -180,10 +180,10 @@ public function testGetAllSnaksReturnsAllSnaks() { public function testAddStatementWithOnlyMainSnak() { $list = new StatementList(); - $list->addNewStatement( $this->newSnak( 'P42', 'foo' ) ); + $list->addNewStatement( self::newSnak( 'P42', 'foo' ) ); $this->assertEquals( - new StatementList( new Statement( $this->newSnak( 'P42', 'foo' ) ) ), + new StatementList( new Statement( self::newSnak( 'P42', 'foo' ) ) ), $list ); } @@ -192,18 +192,18 @@ public function testAddStatementWithQualifiersAsSnakArray() { $list = new StatementList(); $list->addNewStatement( - $this->newSnak( 'P42', 'foo' ), + self::newSnak( 'P42', 'foo' ), [ - $this->newSnak( 'P1', 'bar' ), + self::newSnak( 'P1', 'bar' ), ] ); $this->assertEquals( new StatementList( new Statement( - $this->newSnak( 'P42', 'foo' ), + self::newSnak( 'P42', 'foo' ), new SnakList( [ - $this->newSnak( 'P1', 'bar' ), + self::newSnak( 'P1', 'bar' ), ] ) ) ), @@ -214,16 +214,16 @@ public function testAddStatementWithQualifiersAsSnakArray() { public function testAddStatementWithQualifiersAsSnakList() { $list = new StatementList(); $snakList = new SnakList( [ - $this->newSnak( 'P1', 'bar' ), + self::newSnak( 'P1', 'bar' ), ] ); $list->addNewStatement( - $this->newSnak( 'P42', 'foo' ), + self::newSnak( 'P42', 'foo' ), $snakList ); $this->assertEquals( - new StatementList( new Statement( $this->newSnak( 'P42', 'foo' ), $snakList ) ), + new StatementList( new Statement( self::newSnak( 'P42', 'foo' ), $snakList ) ), $list ); } @@ -232,13 +232,13 @@ public function testAddStatementWithGuid() { $list = new StatementList(); $list->addNewStatement( - $this->newSnak( 'P42', 'foo' ), + self::newSnak( 'P42', 'foo' ), null, null, 'kittens' ); - $statement = new Statement( $this->newSnak( 'P42', 'foo' ) ); + $statement = new Statement( self::newSnak( 'P42', 'foo' ) ); $statement->setGuid( 'kittens' ); @@ -288,12 +288,12 @@ public function testReplaceStatement() { $statement2 = new Statement( new PropertyNoValueSnak( 2 ) ); $statement3 = new Statement( new PropertyNoValueSnak( 3 ) ); $oldStatement = new Statement( - $this->newSnak( 'P42', 'foo' ), + self::newSnak( 'P42', 'foo' ), null, null, (string)$statementGuid ); - $newStatement = new Statement( $this->newSnak( 'P42', 'bar' ) ); + $newStatement = new Statement( self::newSnak( 'P42', 'bar' ) ); $list = new StatementList( $statement1, $statement2, $statement3 ); $list->addStatement( $oldStatement, $index ); @@ -358,9 +358,9 @@ public function testGivenNewStatementWithDifferentProperty_replaceStatementThrow } public function testGivenGuidOfPresentStatement_statementIsRemoved() { - $statement1 = new Statement( $this->newSnak( 'P24', 'foo' ), null, null, 'foo' ); - $statement2 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); - $statement3 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement1 = new Statement( self::newSnak( 'P24', 'foo' ), null, null, 'foo' ); + $statement2 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement3 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); $list = new StatementList( $statement1, $statement2, $statement3 ); $list->removeStatementsWithGuid( 'foo' ); @@ -369,9 +369,9 @@ public function testGivenGuidOfPresentStatement_statementIsRemoved() { } public function testGivenGuidOfMultipleStatements_multipleStatementsAreRemoved() { - $statement1 = new Statement( $this->newSnak( 'P24', 'foo' ), null, null, 'foo' ); - $statement2 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); - $statement3 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement1 = new Statement( self::newSnak( 'P24', 'foo' ), null, null, 'foo' ); + $statement2 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement3 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); $list = new StatementList( $statement1, $statement2, $statement3 ); $list->removeStatementsWithGuid( 'bar' ); @@ -380,9 +380,9 @@ public function testGivenGuidOfMultipleStatements_multipleStatementsAreRemoved() } public function testGivenNotPresentGuid_listIsNotModified() { - $statement1 = new Statement( $this->newSnak( 'P24', 'foo' ), null, null, 'foo' ); - $statement2 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); - $statement3 = new Statement( $this->newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement1 = new Statement( self::newSnak( 'P24', 'foo' ), null, null, 'foo' ); + $statement2 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); + $statement3 = new Statement( self::newSnak( 'P32', 'bar' ), null, null, 'bar' ); $list = new StatementList( $statement1, $statement2, $statement3 ); $list->removeStatementsWithGuid( 'baz' ); @@ -391,9 +391,9 @@ public function testGivenNotPresentGuid_listIsNotModified() { } public function testGivenNullGuid_allStatementsWithNoGuidAreRemoved() { - $statement1 = new Statement( $this->newSnak( 'P24', 'foo' ), null, null, 'foo' ); - $statement2 = new Statement( $this->newSnak( 'P32', 'bar' ) ); - $statement3 = new Statement( $this->newSnak( 'P32', 'bar' ) ); + $statement1 = new Statement( self::newSnak( 'P24', 'foo' ), null, null, 'foo' ); + $statement2 = new Statement( self::newSnak( 'P32', 'bar' ) ); + $statement3 = new Statement( self::newSnak( 'P32', 'bar' ) ); $list = new StatementList( $statement1, $statement2, $statement3 ); $list->removeStatementsWithGuid( null ); @@ -403,8 +403,8 @@ public function testGivenNullGuid_allStatementsWithNoGuidAreRemoved() { public function testCanConstructWithUnpackedTraversableContainingOnlyStatements() { $statementArray = [ - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), ]; $object = new ArrayObject( $statementArray ); @@ -418,7 +418,7 @@ public function testCanConstructWithUnpackedTraversableContainingOnlyStatements( } public function testCanConstructWithStatement() { - $statement = new Statement( $this->newSnak( 'P42', 'foo' ) ); + $statement = new Statement( self::newSnak( 'P42', 'foo' ) ); $this->assertEquals( new StatementList( $statement ), @@ -427,9 +427,9 @@ public function testCanConstructWithStatement() { } public function testCanConstructWithStatementArgumentList() { - $statement0 = new Statement( $this->newSnak( 'P42', 'foo' ) ); - $statement1 = new Statement( $this->newSnak( 'P42', 'bar' ) ); - $statement2 = new Statement( $this->newSnak( 'P42', 'baz' ) ); + $statement0 = new Statement( self::newSnak( 'P42', 'foo' ) ); + $statement1 = new Statement( self::newSnak( 'P42', 'bar' ) ); + $statement2 = new Statement( self::newSnak( 'P42', 'baz' ) ); $this->assertEquals( new StatementList( $statement0, $statement1, $statement2 ), @@ -445,8 +445,8 @@ public function testCountForEmptyList() { public function testCountForNonEmptyList() { $list = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $this->assertSame( 2, $list->count() ); @@ -462,28 +462,28 @@ public function testGivenIdenticalLists_equalsReturnsTrue( array $statements ) { $this->assertTrue( $firstStatements->equals( $secondStatements ) ); } - public function provideArrayOfStatements(): array { + public static function provideArrayOfStatements(): array { return [ "two statements" => [ [ - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), ], ], - "one statement" => [ [ $this->getStatementWithSnak( 'P1', 'foo' ) ] ], + "one statement" => [ [ self::getStatementWithSnak( 'P1', 'foo' ) ] ], "no statements (empty array)" => [ [] ], ]; } public function testGivenDifferentLists_equalsReturnsFalse() { $firstStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $secondStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'SPAM' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'SPAM' ) ); $this->assertFalse( $firstStatements->equals( $secondStatements ) ); @@ -491,15 +491,15 @@ public function testGivenDifferentLists_equalsReturnsFalse() { public function testGivenListsWithDifferentDuplicates_equalsReturnsFalse() { $firstStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $secondStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $this->assertFalse( $firstStatements->equals( $secondStatements ) ); @@ -507,15 +507,15 @@ public function testGivenListsWithDifferentDuplicates_equalsReturnsFalse() { public function testGivenListsWithDifferentOrder_equalsReturnsFalse() { $firstStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P2', 'bar' ), - $this->getStatementWithSnak( 'P3', 'baz' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P2', 'bar' ), + self::getStatementWithSnak( 'P3', 'baz' ) ); $secondStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P3', 'baz' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P3', 'baz' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $this->assertFalse( $firstStatements->equals( $secondStatements ) ); @@ -525,9 +525,9 @@ public function testEmptyListDoesNotEqualNonEmptyList() { $firstStatements = new StatementList(); $secondStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P3', 'baz' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P3', 'baz' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $this->assertFalse( $firstStatements->equals( $secondStatements ) ); @@ -535,9 +535,9 @@ public function testEmptyListDoesNotEqualNonEmptyList() { public function testNonEmptyListDoesNotEqualEmptyList() { $firstStatements = new StatementList( - $this->getStatementWithSnak( 'P1', 'foo' ), - $this->getStatementWithSnak( 'P3', 'baz' ), - $this->getStatementWithSnak( 'P2', 'bar' ) + self::getStatementWithSnak( 'P1', 'foo' ), + self::getStatementWithSnak( 'P3', 'baz' ), + self::getStatementWithSnak( 'P2', 'bar' ) ); $secondStatements = new StatementList(); @@ -552,7 +552,7 @@ public function testEmptyListIsEmpty() { } public function testNonEmptyListIsNotEmpty() { - $list = new StatementList( $this->getStatementWithSnak( 'P1', 'foo' ) ); + $list = new StatementList( self::getStatementWithSnak( 'P1', 'foo' ) ); $this->assertFalse( $list->isEmpty() ); } diff --git a/tests/unit/Statement/StatementTest.php b/tests/unit/Statement/StatementTest.php index 2f0b7253..377356ec 100644 --- a/tests/unit/Statement/StatementTest.php +++ b/tests/unit/Statement/StatementTest.php @@ -333,8 +333,8 @@ public function testStatementWithDifferentReferences_equalsReturnsFalse() { } public function testEquals() { - $statement = $this->newStatement(); - $target = $this->newStatement(); + $statement = self::newStatement(); + $target = self::newStatement(); $this->assertTrue( $statement->equals( $target ) ); } @@ -349,19 +349,19 @@ public function testNotEquals( Statement $statement, Statement $target ) { /** * @return array array of arrays: [ [ Statement $statement, Statement $target ], ... ] */ - public function provideNonEqualStatements(): array { - $statement = $this->newStatement(); + public static function provideNonEqualStatements(): array { + $statement = self::newStatement(); - $statementWithoutQualifiers = $this->newStatement(); + $statementWithoutQualifiers = self::newStatement(); $statementWithoutQualifiers->setQualifiers( new SnakList() ); - $statementWithoutReferences = $this->newStatement(); + $statementWithoutReferences = self::newStatement(); $statementWithoutReferences->setReferences( new ReferenceList() ); - $statementWithPreferredRank = $this->newStatement(); + $statementWithPreferredRank = self::newStatement(); $statementWithPreferredRank->setRank( Statement::RANK_PREFERRED ); - $statementMainSnakNotEqual = $this->newStatement(); + $statementMainSnakNotEqual = self::newStatement(); $statementMainSnakNotEqual->setMainSnak( new PropertyNoValueSnak( 9000 ) ); return [ @@ -372,7 +372,7 @@ public function provideNonEqualStatements(): array { ]; } - private function newStatement(): Statement { + private static function newStatement(): Statement { $statement = new Statement( new PropertyNoValueSnak( 42 ), new SnakList( [ new PropertyNoValueSnak( 23 ) ] ),