Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/65674
Change subject: Added test config and bootstrap for the DataModel component ...................................................................... Added test config and bootstrap for the DataModel component This commit fixes most of the dependency issues where DataModel code was still using things from core or wikibase lib. Some issues are however more serious and fixing them is definitly out of scope for this commit, so the tests invoking this code have been excluded from the WikibaseDataModelWithoutMW testsuite for now. Change-Id: I44397a6b6384cb0210e7a08a552bea90515e4716 --- M DataModel/DataModel.classes.php M DataModel/DataModel.mw.php R DataModel/DataModel/ByPropertyIdArray.php M DataModel/DataModel/Claim/Statement.php M DataModel/DataModel/Entity/Entity.php M DataModel/DataModel/Entity/Property.php R DataModel/DataModel/EntityDiff.php R DataModel/DataModel/ItemDiff.php M DataModel/DataModel/SiteLink.php M DataModel/dependencies.txt A DataModel/phpunit.xml.dist A DataModel/tests/bootstrap.php R DataModel/tests/phpunit/ByPropertyIdArrayTest.php M DataModel/tests/phpunit/Claim/ClaimAggregateTest.php M DataModel/tests/phpunit/Claim/ClaimListAccessTest.php M DataModel/tests/phpunit/Claim/ClaimTest.php M DataModel/tests/phpunit/Claim/ClaimsTest.php M DataModel/tests/phpunit/Claim/StatementTest.php M DataModel/tests/phpunit/Entity/EntityIdTest.php M DataModel/tests/phpunit/Entity/EntityTest.php M DataModel/tests/phpunit/Entity/ItemMultilangTextsTest.php M DataModel/tests/phpunit/Entity/ItemNewEmptyTest.php M DataModel/tests/phpunit/Entity/ItemNewFromArrayTest.php M DataModel/tests/phpunit/Entity/PropertyTest.php R DataModel/tests/phpunit/EntityDiffOldTest.php R DataModel/tests/phpunit/EntityDiffTest.php M DataModel/tests/phpunit/HashableObjectStorageTest.php R DataModel/tests/phpunit/ItemDiffTest.php M DataModel/tests/phpunit/MapValueHasherTest.php M DataModel/tests/phpunit/ReferenceListTest.php M DataModel/tests/phpunit/ReferenceTest.php M DataModel/tests/phpunit/SiteLinkTest.php M DataModel/tests/phpunit/Snak/PropertyValueSnakTest.php M DataModel/tests/phpunit/Snak/SnakListTest.php M DataModel/tests/phpunit/Snak/SnakObjectTest.php M DataModel/tests/phpunit/Snak/SnakTest.php M DataModel/tests/phpunit/hasharray/HashArrayTest.php A DataModel/tests/testLoader.php M lib/WikibaseLib.classes.php M lib/WikibaseLib.hooks.php 40 files changed, 229 insertions(+), 177 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/74/65674/1 diff --git a/DataModel/DataModel.classes.php b/DataModel/DataModel.classes.php index da44d8c..eb9ef89 100644 --- a/DataModel/DataModel.classes.php +++ b/DataModel/DataModel.classes.php @@ -53,8 +53,11 @@ 'Wikibase\SnakRole' => 'DataModel/Snak/SnakRole.php', 'Wikibase\Snaks' => 'DataModel/Snak/Snaks.php', + 'Wikibase\ByPropertyIdArray' => 'DataModel/ByPropertyIdArray.php', + 'Wikibase\EntityDiff' => 'DataModel/EntityDiff.php', 'Wikibase\HashableObjectStorage' => 'DataModel/HashableObjectStorage.php', 'Wikibase\HashArray' => 'DataModel/HashArray.php', + 'Wikibase\ItemDiff' => 'DataModel/ItemDiff.php', 'Wikibase\MapHasher' => 'DataModel/MapHasher.php', 'Wikibase\MapValueHasher' => 'DataModel/MapValueHasher.php', 'Wikibase\Reference' => 'DataModel/Reference.php', diff --git a/DataModel/DataModel.mw.php b/DataModel/DataModel.mw.php index c213f54..02aeffa 100644 --- a/DataModel/DataModel.mw.php +++ b/DataModel/DataModel.mw.php @@ -44,13 +44,7 @@ } if ( defined( 'MW_PHPUNIT_TEST' ) ) { - $wgAutoloadClasses['Wikibase\Test\ClaimTest'] = __DIR__ . '/tests/phpunit/Claim/ClaimTest.php'; - $wgAutoloadClasses['Wikibase\Test\EntityTest'] = __DIR__ . '/tests/phpunit/Entity/EntityTest.php'; - $wgAutoloadClasses['Wikibase\Test\TestItems'] = __DIR__ . '/tests/phpunit/Entity/TestItems.php'; - $wgAutoloadClasses['Wikibase\Test\SnakObjectTest'] = __DIR__ . '/tests/phpunit/Snak/SnakObjectTest.php'; - - $wgAutoloadClasses['Wikibase\Test\HashArrayTest'] = __DIR__ . '/tests/phpunit/hasharray/HashArrayTest.php'; - $wgAutoloadClasses['Wikibase\Test\HashArrayElement'] = __DIR__ . '/tests/phpunit/hasharray/HashArrayElement.php'; + require_once __DIR__ . '/tests/testLoader.php'; } /** @@ -72,6 +66,7 @@ 'Claim/Claim', 'Claim/Statement', + 'Entity/ByPropertyIdArray', 'Entity/EntityId', 'Entity/ItemMultilangTexts', 'Entity/ItemNewEmpty', diff --git a/lib/includes/ByPropertyIdArray.php b/DataModel/DataModel/ByPropertyIdArray.php similarity index 100% rename from lib/includes/ByPropertyIdArray.php rename to DataModel/DataModel/ByPropertyIdArray.php diff --git a/DataModel/DataModel/Claim/Statement.php b/DataModel/DataModel/Claim/Statement.php index e3c1f79..a4bcb5f 100644 --- a/DataModel/DataModel/Claim/Statement.php +++ b/DataModel/DataModel/Claim/Statement.php @@ -2,6 +2,8 @@ namespace Wikibase; +use InvalidArgumentException; + /** * Class representing a Wikibase statement. * See https://meta.wikimedia.org/wiki/Wikidata/Data_model#Statements @@ -95,13 +97,13 @@ * @since 0.1 * * @param integer $rank - * @throws \MWException + * @throws InvalidArgumentException */ public function setRank( $rank ) { $ranks = array( Statement::RANK_DEPRECATED, Statement::RANK_NORMAL, Statement::RANK_PREFERRED ); if ( !in_array( $rank, $ranks, true ) ) { - throw new \MWException( 'Invalid rank specified for statement: ' . var_export( $rank, true ) ); + throw new InvalidArgumentException( 'Invalid rank specified for statement: ' . var_export( $rank, true ) ); } $this->rank = $rank; diff --git a/DataModel/DataModel/Entity/Entity.php b/DataModel/DataModel/Entity/Entity.php index 5fd1828..76d0e7e 100644 --- a/DataModel/DataModel/Entity/Entity.php +++ b/DataModel/DataModel/Entity/Entity.php @@ -606,8 +606,6 @@ * @return Entity */ public function copy() { - wfProfileIn( __METHOD__ ); - $array = array(); foreach ( $this->toArray() as $key => $value ) { @@ -616,7 +614,6 @@ $copy = new static( $array ); - wfProfileOut( __METHOD__ ); return $copy; } diff --git a/DataModel/DataModel/Entity/Property.php b/DataModel/DataModel/Entity/Property.php index 162c881..1c24957 100644 --- a/DataModel/DataModel/Entity/Property.php +++ b/DataModel/DataModel/Entity/Property.php @@ -53,7 +53,7 @@ * @deprecated since 0.4 * * @return DataType - * @throws MWException + * @throws InvalidArgumentException */ public function getDataType() { if ( $this->dataType === null ) { @@ -63,11 +63,11 @@ $this->dataType = $registry->getDataTypeFactory()->getType( $this->data['datatype'] ); if ( $this->dataType === null ) { - throw new MWException( 'The DataType of the property is not valid' ); + throw new InvalidArgumentException( 'The DataType of the property is not valid' ); } } else { - throw new MWException( 'The DataType of the property is not known' ); + throw new InvalidArgumentException( 'The DataType of the property is not known' ); } } diff --git a/lib/includes/EntityDiff.php b/DataModel/DataModel/EntityDiff.php similarity index 100% rename from lib/includes/EntityDiff.php rename to DataModel/DataModel/EntityDiff.php diff --git a/lib/includes/ItemDiff.php b/DataModel/DataModel/ItemDiff.php similarity index 100% rename from lib/includes/ItemDiff.php rename to DataModel/DataModel/ItemDiff.php diff --git a/DataModel/DataModel/SiteLink.php b/DataModel/DataModel/SiteLink.php index 6858e26..5797462 100644 --- a/DataModel/DataModel/SiteLink.php +++ b/DataModel/DataModel/SiteLink.php @@ -58,8 +58,6 @@ throw new \Exception( 'Support for $normalize parameter has been dropped' ); } - wfProfileIn( __METHOD__ ); - $site = Sites::singleton()->getSite( $globalSiteId ); if ( !$site ) { @@ -77,10 +75,7 @@ $page = $normalized; } - $link = new SiteLink( $site, $page ); - - wfProfileOut( __METHOD__ ); - return $link; + return new SiteLink( $site, $page ); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/DataModel/dependencies.txt b/DataModel/dependencies.txt index c4abc9e..f121696 100644 --- a/DataModel/dependencies.txt +++ b/DataModel/dependencies.txt @@ -3,7 +3,7 @@ * WikibaseLib (this dependency is something we want to get rid of) * MediaWiki (this dependency is something we want to get rid of) * DataValues library +* Diff library * DataTypes library (this dependency is something we want to get rid of) -* Ask library (only the Query class has this dependency, we want to move this one out) And nothing else. \ No newline at end of file diff --git a/DataModel/phpunit.xml.dist b/DataModel/phpunit.xml.dist new file mode 100644 index 0000000..087c229 --- /dev/null +++ b/DataModel/phpunit.xml.dist @@ -0,0 +1,28 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="false" + bootstrap="tests/bootstrap.php" + cacheTokens="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="false" + convertWarningsToExceptions="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + strict="true" + verbose="true"> + <testsuites> + <testsuite name="WikibaseDataModelWithoutMW"> + <directory>tests/phpunit</directory> + <exclude>tests/phpunit/Entity/ItemTest.php</exclude> + <exclude>tests/phpunit/Entity/PropertyTest.php</exclude> + <exclude>tests/phpunit/Entity/ItemNewEmptyTest.php</exclude> + <exclude>tests/phpunit/ItemDiffTest.php</exclude> + <exclude>tests/phpunit/SiteLinkTest.php</exclude> + </testsuite> + <testsuite name="WikibaseDataModelAll"> + <directory>tests/phpunit</directory> + </testsuite> + </testsuites> +</phpunit> diff --git a/DataModel/tests/bootstrap.php b/DataModel/tests/bootstrap.php new file mode 100644 index 0000000..dc5aeb9 --- /dev/null +++ b/DataModel/tests/bootstrap.php @@ -0,0 +1,23 @@ +<?php + +/** + * PHPUnit test bootstrap file for the Wikibase DataModel component. + * + * @since 0.1 + * + * @file + * @ingroup DataModel + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ + +require_once( __DIR__ . '/../../../DataValues/DataValues/DataValues.php' ); + +require_once( __DIR__ . '/../../../Diff/Diff.php' ); + +require_once( __DIR__ . '/../DataModel.php' ); + +require_once( __DIR__ . '/testLoader.php' ); + +// If something needs to change here, a reflecting change needs to be added to ../dependencies.txt. \ No newline at end of file diff --git a/lib/tests/phpunit/ByPropertyIdArrayTest.php b/DataModel/tests/phpunit/ByPropertyIdArrayTest.php similarity index 89% rename from lib/tests/phpunit/ByPropertyIdArrayTest.php rename to DataModel/tests/phpunit/ByPropertyIdArrayTest.php index 73a3d3f..403b518 100644 --- a/lib/tests/phpunit/ByPropertyIdArrayTest.php +++ b/DataModel/tests/phpunit/ByPropertyIdArrayTest.php @@ -34,7 +34,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ByPropertyIdArrayTest extends \MediaWikiTestCase { +class ByPropertyIdArrayTest extends \PHPUnit_Framework_TestCase { public function listProvider() { $lists = array(); @@ -43,8 +43,8 @@ new \Wikibase\PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 42 ) ), new \Wikibase\PropertySomeValueSnak( new EntityId( Property::ENTITY_TYPE, 42 ) ), new \Wikibase\PropertySomeValueSnak( new EntityId( Property::ENTITY_TYPE, 10 ) ), - new \Wikibase\PropertySomeValueSnak( new EntityId( Property::ENTITY_TYPE, 1 ) ), new \Wikibase\PropertyValueSnak( new EntityId( Property::ENTITY_TYPE, 10 ), new \DataValues\StringValue( 'ohi' ) ), + new \Wikibase\PropertySomeValueSnak( new EntityId( Property::ENTITY_TYPE, 1 ) ), ); $lists[] = $snaks; @@ -63,7 +63,13 @@ $snaks ); - return $this->arrayWrap( $lists ); + $argLists = array(); + + foreach ( $lists as $list ) { + $argLists[] = array( $list ); + } + + return $argLists; } /** @@ -83,7 +89,10 @@ $indexedArray->buildIndex(); - $this->assertArrayEquals( $expected, $indexedArray->getPropertyIds() ); + $this->assertEquals( + array_values( $expected ), + array_values( $indexedArray->getPropertyIds() ) + ); } /** @@ -112,7 +121,10 @@ } } - $this->assertArrayEquals( $objects, $allObtainedObjects ); + $this->assertEquals( + array_values( $objects ), + array_values( $allObtainedObjects ) + ); } public function testGetByNotSetIdThrowsException() { diff --git a/DataModel/tests/phpunit/Claim/ClaimAggregateTest.php b/DataModel/tests/phpunit/Claim/ClaimAggregateTest.php index ef256d9..52d2e6c 100644 --- a/DataModel/tests/phpunit/Claim/ClaimAggregateTest.php +++ b/DataModel/tests/phpunit/Claim/ClaimAggregateTest.php @@ -36,7 +36,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ClaimAggregateTest extends \MediaWikiTestCase { +class ClaimAggregateTest extends \PHPUnit_Framework_TestCase { public function ClaimTestProvider() { $claims = array(); @@ -104,7 +104,7 @@ $freshlyObtained = new \Wikibase\Claims( $aggregate->getClaims() ); - $this->assertArrayEquals( + $this->assertEquals( iterator_to_array( $unmodifiedClaims ), iterator_to_array( $freshlyObtained ), 'Was able to modify statements via ClaimAggregate::getClaims' diff --git a/DataModel/tests/phpunit/Claim/ClaimListAccessTest.php b/DataModel/tests/phpunit/Claim/ClaimListAccessTest.php index 99baa57..61b4989 100644 --- a/DataModel/tests/phpunit/Claim/ClaimListAccessTest.php +++ b/DataModel/tests/phpunit/Claim/ClaimListAccessTest.php @@ -35,7 +35,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ClaimListAccessTest extends \MediaWikiTestCase { +class ClaimListAccessTest extends \PHPUnit_Framework_TestCase { public function claimTestProvider() { $claims = array(); diff --git a/DataModel/tests/phpunit/Claim/ClaimTest.php b/DataModel/tests/phpunit/Claim/ClaimTest.php index 72aa45d..bfb2650 100644 --- a/DataModel/tests/phpunit/Claim/ClaimTest.php +++ b/DataModel/tests/phpunit/Claim/ClaimTest.php @@ -39,7 +39,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ClaimTest extends \MediaWikiTestCase { +class ClaimTest extends \PHPUnit_Framework_TestCase { public function constructorProvider() { $argLists = array(); @@ -160,7 +160,7 @@ */ public function testGetGuid( Claim $claim ) { $guid = $claim->getGuid(); - $this->assertTypeOrValue( 'string', $guid, null ); + $this->assertTrue( $guid === null || is_string( $guid ) ); $this->assertEquals( $guid, $claim->getGuid() ); $claim->setGuid( 'foobar' ); @@ -190,14 +190,11 @@ } public function testGetHashStability() { - $guidGenerator = new \Wikibase\Lib\ClaimGuidGenerator( new \Wikibase\EntityId( \Wikibase\Item::ENTITY_TYPE, 31 ) ); - $guid = $guidGenerator->newGuid(); - $claim0 = new Claim( new \Wikibase\PropertyNoValueSnak( 42 ) ); - $claim0->setGuid( $guid ); + $claim0->setGuid( 'claim0' ); $claim1 = new Claim( new \Wikibase\PropertyNoValueSnak( 42 ) ); - $claim1->setGuid( $guid ); + $claim1->setGuid( 'claim1' ); $this->assertEquals( $claim0->getHash(), $claim1->getHash() ); } diff --git a/DataModel/tests/phpunit/Claim/ClaimsTest.php b/DataModel/tests/phpunit/Claim/ClaimsTest.php index 091030a..8a895b7 100644 --- a/DataModel/tests/phpunit/Claim/ClaimsTest.php +++ b/DataModel/tests/phpunit/Claim/ClaimsTest.php @@ -36,7 +36,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ClaimsTest extends \MediaWikiTestCase { +class ClaimsTest extends \PHPUnit_Framework_TestCase { public function getInstanceClass() { return '\Wikibase\Claims'; @@ -153,7 +153,7 @@ */ public function testGetMainSnaks( Claims $array ) { $snaks = $array->getMainSnaks(); - $this->assertType( 'array', $snaks ); + $this->assertInternalType( 'array', $snaks ); $this->assertSameSize( $array, $snaks ); } @@ -207,12 +207,11 @@ new \Wikibase\SnakList( array( new \Wikibase\PropertyValueSnak( 10, new \DataValues\StringValue( 'spam' ) ) ) ) ) ) ) ); - $guidGen = new \Wikibase\Lib\V4GuidGenerator(); - $claim0->setGuid( $guidGen->newGuid() ); - $claim1->setGuid( $guidGen->newGuid() ); - $claim2->setGuid( $guidGen->newGuid() ); - $statement1->setGuid( $guidGen->newGuid() ); - $statement0->setGuid( $guidGen->newGuid() ); + $claim0->setGuid( 'claim0' ); + $claim1->setGuid( 'claim1' ); + $claim2->setGuid( 'claim2' ); + $statement1->setGuid( 'statement1' ); + $statement0->setGuid( 'statement0' ); $claim2v2 = unserialize( serialize( $claim2 ) ); $claim2v2->setMainSnak( new \Wikibase\PropertyValueSnak( 42, new \DataValues\StringValue( 'omnomnom' ) ) ); @@ -294,7 +293,7 @@ $actual = $source->getDiff( $target ); // Note: this makes order of inner arrays relevant, and this order is not guaranteed by the interface - $this->assertArrayEquals( $expected->getOperations(), $actual->getOperations(), false, true, $message ); + $this->assertEquals( $expected->getOperations(), $actual->getOperations(), $message ); } } diff --git a/DataModel/tests/phpunit/Claim/StatementTest.php b/DataModel/tests/phpunit/Claim/StatementTest.php index 837111a..bc13682 100644 --- a/DataModel/tests/phpunit/Claim/StatementTest.php +++ b/DataModel/tests/phpunit/Claim/StatementTest.php @@ -68,7 +68,13 @@ $instances[] = $instance; - return $this->arrayWrap( $instances ); + $argLists = array(); + + foreach ( $instances as $instance ) { + $argLists[] = array( $instance ); + } + + return $argLists; } /** @@ -114,15 +120,14 @@ public function testSetRank( Statement $statement ) { $statement->setRank( Statement::RANK_DEPRECATED ); $this->assertEquals( Statement::RANK_DEPRECATED, $statement->getRank() ); + } - $pokemons = null; - - try { - $statement->setRank( 9001 ); - } - catch ( \Exception $pokemons ) {} - - $this->assertInstanceOf( '\MWException', $pokemons ); + /** + * @dataProvider instanceProvider + */ + public function testSetInvalidRank( Statement $statement ) { + $this->setExpectedException( 'InvalidArgumentException' ); + $statement->setRank( 9001 ); } /** @@ -156,15 +161,12 @@ } public function testGetHash() { - $guidGenerator = new \Wikibase\Lib\ClaimGuidGenerator( new \Wikibase\EntityId( \Wikibase\Item::ENTITY_TYPE, 31 ) ); - $guid = $guidGenerator->newGuid(); - $claim0 = new Statement( new \Wikibase\PropertyNoValueSnak( 42 ) ); - $claim0->setGuid( $guid ); + $claim0->setGuid( 'claim0' ); $claim0->setRank( Statement::RANK_DEPRECATED ); $claim1 = new Statement( new \Wikibase\PropertyNoValueSnak( 42 ) ); - $claim1->setGuid( $guid ); + $claim1->setGuid( 'claim1' ); $claim1->setRank( Statement::RANK_DEPRECATED ); $this->assertEquals( $claim0->getHash(), $claim1->getHash() ); diff --git a/DataModel/tests/phpunit/Entity/EntityIdTest.php b/DataModel/tests/phpunit/Entity/EntityIdTest.php index 68a67eb..07083c9 100644 --- a/DataModel/tests/phpunit/Entity/EntityIdTest.php +++ b/DataModel/tests/phpunit/Entity/EntityIdTest.php @@ -34,7 +34,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author John Erling Blad < jeb...@gmail.com > */ -class EntityIdTest extends \MediaWikiTestCase { +class EntityIdTest extends \PHPUnit_Framework_TestCase { public function constructorProvider() { $argLists = array(); diff --git a/DataModel/tests/phpunit/Entity/EntityTest.php b/DataModel/tests/phpunit/Entity/EntityTest.php index b0277da..1a265db 100644 --- a/DataModel/tests/phpunit/Entity/EntityTest.php +++ b/DataModel/tests/phpunit/Entity/EntityTest.php @@ -48,7 +48,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -abstract class EntityTest extends \MediaWikiTestCase { +abstract class EntityTest extends \PHPUnit_Framework_TestCase { /** * @since 0.1 @@ -448,7 +448,13 @@ $entities[] = $entity; - return $this->arrayWrap( $entities ); + $argLists = array(); + + foreach ( $entities as $entity ) { + $argLists[] = array( $entity ); + } + + return $argLists; } /** @@ -510,7 +516,13 @@ $ids[] = new EntityId( $type, $id ); } - return $this->arrayWrap( $ids ); + $argLists = array(); + + foreach ( $ids as $id ) { + $argLists[] = array( $id ); + } + + return $argLists; } /** diff --git a/DataModel/tests/phpunit/Entity/ItemMultilangTextsTest.php b/DataModel/tests/phpunit/Entity/ItemMultilangTextsTest.php index 577a2a1..2f321c9 100644 --- a/DataModel/tests/phpunit/Entity/ItemMultilangTextsTest.php +++ b/DataModel/tests/phpunit/Entity/ItemMultilangTextsTest.php @@ -34,7 +34,7 @@ * @licence GNU GPL v2+ * @author John Erling Blad < jeb...@gmail.com > */ -class ItemMultilangTextsTest extends \MediaWikiTestCase { +class ItemMultilangTextsTest extends \PHPUnit_Framework_TestCase { //@todo: make this a baseclass to use with all types of entitites. diff --git a/DataModel/tests/phpunit/Entity/ItemNewEmptyTest.php b/DataModel/tests/phpunit/Entity/ItemNewEmptyTest.php index 7039bbe..237c329 100644 --- a/DataModel/tests/phpunit/Entity/ItemNewEmptyTest.php +++ b/DataModel/tests/phpunit/Entity/ItemNewEmptyTest.php @@ -38,7 +38,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author John Erling Blad < jeb...@gmail.com > */ -class ItemNewEmptyTest extends \MediaWikiTestCase { +class ItemNewEmptyTest extends \PHPUnit_Framework_TestCase { //@todo: make this a baseclass to use with all types of entitites. diff --git a/DataModel/tests/phpunit/Entity/ItemNewFromArrayTest.php b/DataModel/tests/phpunit/Entity/ItemNewFromArrayTest.php index 10d0abc..218eeb0 100644 --- a/DataModel/tests/phpunit/Entity/ItemNewFromArrayTest.php +++ b/DataModel/tests/phpunit/Entity/ItemNewFromArrayTest.php @@ -35,7 +35,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author John Erling Blad < jeb...@gmail.com > */ -class ItemNewFromArrayTest extends \MediaWikiTestCase { +class ItemNewFromArrayTest extends \PHPUnit_Framework_TestCase { //@todo: make this a baseclass to use with all types of entitites. diff --git a/DataModel/tests/phpunit/Entity/PropertyTest.php b/DataModel/tests/phpunit/Entity/PropertyTest.php index 6bb775f..0993b24 100644 --- a/DataModel/tests/phpunit/Entity/PropertyTest.php +++ b/DataModel/tests/phpunit/Entity/PropertyTest.php @@ -66,43 +66,6 @@ return Property::newFromArray( $data ); } - public function testGetDataType() { - $property = $this->getNewEmpty(); - - $pokemons = null; - - try { - $property->getDataType(); - } - catch ( \Exception $pokemons ) {} - - $this->assertInstanceOf( '\MWException', $pokemons ); - - foreach ( \Wikibase\Settings::get( 'dataTypes' ) as $dataTypeId ) { - $libRegistry = new \Wikibase\LibRegistry( \Wikibase\Settings::singleton() ); - $dataType = $libRegistry->getDataTypeFactory()->getType( $dataTypeId ); - - $property->setDataType( $dataType ); - - $this->assertInstanceOf( '\DataTypes\DataType', $property->getDataType() ); - } - } - - public function testSetDataType() { - $property = $this->getNewEmpty(); - - $libRegistry = new \Wikibase\LibRegistry( \Wikibase\Settings::singleton() ); - $dataTypeFactory = $libRegistry->getDataTypeFactory(); - - foreach ( \Wikibase\Settings::get( 'dataTypes' ) as $dataTypeId ) { - $dataType = $dataTypeFactory->getType( $dataTypeId ); - - $property->setDataType( $dataType ); - - $this->assertEquals( $dataType, $property->getDataType() ); - } - } - public function propertyProvider() { $objects = array(); @@ -141,8 +104,7 @@ $argLists[] = array( clone $property, new EntityId( Item::ENTITY_TYPE, 9001 ) ); - $libRegistry = new \Wikibase\LibRegistry( \Wikibase\Settings::singleton() ); - $property->setDataType( $libRegistry->getDataTypeFactory()->getType( 'commonsMedia' ) ); + $property->setDataTypeId( 'commonsMedia' ); return $argLists; } diff --git a/lib/tests/phpunit/entity/EntityDiffOldTest.php b/DataModel/tests/phpunit/EntityDiffOldTest.php similarity index 95% rename from lib/tests/phpunit/entity/EntityDiffOldTest.php rename to DataModel/tests/phpunit/EntityDiffOldTest.php index b341112..b8bf184 100644 --- a/lib/tests/phpunit/entity/EntityDiffOldTest.php +++ b/DataModel/tests/phpunit/EntityDiffOldTest.php @@ -36,7 +36,7 @@ * @author Jens Ohlig <jens.oh...@wikimedia.de> */ -abstract class EntityDiffOldTest extends \MediaWikiTestCase { +abstract class EntityDiffOldTest extends \PHPUnit_Framework_TestCase { private static function newEntity ( $entityType ) { switch ( $entityType ) { @@ -158,9 +158,9 @@ public function testApply( Entity $a, Entity $b ) { $a->patch( $a->getDiff( $b ) ); - $this->assertArrayEquals( $a->getLabels(), $b->getLabels() ); - $this->assertArrayEquals( $a->getDescriptions(), $b->getDescriptions() ); - $this->assertArrayEquals( $a->getAllAliases(), $b->getAllAliases() ); + $this->assertEquals( $a->getLabels(), $b->getLabels() ); + $this->assertEquals( $a->getDescriptions(), $b->getDescriptions() ); + $this->assertEquals( $a->getAllAliases(), $b->getAllAliases() ); } public static function provideConflictDetection() { diff --git a/lib/tests/phpunit/entity/EntityDiffTest.php b/DataModel/tests/phpunit/EntityDiffTest.php similarity index 95% rename from lib/tests/phpunit/entity/EntityDiffTest.php rename to DataModel/tests/phpunit/EntityDiffTest.php index 7ea0fbb..2313b96 100644 --- a/lib/tests/phpunit/entity/EntityDiffTest.php +++ b/DataModel/tests/phpunit/EntityDiffTest.php @@ -32,7 +32,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class EntityDiffTest extends \MediaWikiTestCase { +class EntityDiffTest extends \PHPUnit_Framework_TestCase { public function isEmptyProvider() { $argLists = array(); @@ -105,7 +105,13 @@ $diffs[] = new EntityDiff( $diffOps ); - return $this->arrayWrap( $diffs ); + $argLists = array(); + + foreach ( $diffs as $diff ) { + $argLists[] = array( $diff ); + } + + return $argLists; } /** diff --git a/DataModel/tests/phpunit/HashableObjectStorageTest.php b/DataModel/tests/phpunit/HashableObjectStorageTest.php index 0a43542..1c9e0b5 100644 --- a/DataModel/tests/phpunit/HashableObjectStorageTest.php +++ b/DataModel/tests/phpunit/HashableObjectStorageTest.php @@ -35,7 +35,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class HashableObjectStorageTest extends \MediaWikiTestCase { +class HashableObjectStorageTest extends \PHPUnit_Framework_TestCase { public function testRemoveDuplicates() { $list = new HashableObjectStorage(); diff --git a/lib/tests/phpunit/item/ItemDiffTest.php b/DataModel/tests/phpunit/ItemDiffTest.php similarity index 100% rename from lib/tests/phpunit/item/ItemDiffTest.php rename to DataModel/tests/phpunit/ItemDiffTest.php diff --git a/DataModel/tests/phpunit/MapValueHasherTest.php b/DataModel/tests/phpunit/MapValueHasherTest.php index cf5aefc..287c2c0 100644 --- a/DataModel/tests/phpunit/MapValueHasherTest.php +++ b/DataModel/tests/phpunit/MapValueHasherTest.php @@ -18,19 +18,11 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class MapValueHasherTest extends \MediaWikiTestCase { +class MapValueHasherTest extends \PHPUnit_Framework_TestCase { - public function constructorProvider() { - return $this->arrayWrap( array( false, true ) ); - } - - /** - * @dataProvider constructorProvider - */ - public function testConstructor( $arg0 ) { - $hasher = new MapValueHasher( $arg0 ); - - $this->assertInstanceOf( '\Wikibase\MapHasher', $hasher ); + public function testCanConstructor() { + new MapValueHasher( true ); + $this->assertTrue( true ); } public function testHash() { diff --git a/DataModel/tests/phpunit/ReferenceListTest.php b/DataModel/tests/phpunit/ReferenceListTest.php index 8d7403b..3a75614 100644 --- a/DataModel/tests/phpunit/ReferenceListTest.php +++ b/DataModel/tests/phpunit/ReferenceListTest.php @@ -37,7 +37,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ReferenceListTest extends \MediaWikiTestCase { +class ReferenceListTest extends \PHPUnit_Framework_TestCase { public function getInstanceClass() { return '\Wikibase\ReferenceList'; diff --git a/DataModel/tests/phpunit/ReferenceTest.php b/DataModel/tests/phpunit/ReferenceTest.php index 3be8f8b..b90f487 100644 --- a/DataModel/tests/phpunit/ReferenceTest.php +++ b/DataModel/tests/phpunit/ReferenceTest.php @@ -39,7 +39,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class ReferenceTest extends \MediaWikiTestCase { +class ReferenceTest extends \PHPUnit_Framework_TestCase { public function snakListProvider() { $snakLists = array(); @@ -56,7 +56,13 @@ new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 3 ) ) ) ); - return $this->arrayWrap( $snakLists ); + $argLists = array(); + + foreach ( $snakLists as $snakList ) { + $argLists[] = array( $snakList ); + } + + return $argLists; } public function instanceProvider() { @@ -69,7 +75,13 @@ new StringValue( 'a' ) ) ) ) ); - return $this->arrayWrap( $references ); + $argLists = array(); + + foreach ( $references as $reference ) { + $argLists[] = array( $reference ); + } + + return $argLists; } /** diff --git a/DataModel/tests/phpunit/SiteLinkTest.php b/DataModel/tests/phpunit/SiteLinkTest.php index 47a430e..130b718 100644 --- a/DataModel/tests/phpunit/SiteLinkTest.php +++ b/DataModel/tests/phpunit/SiteLinkTest.php @@ -36,7 +36,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class SiteLinkTest extends \MediaWikiTestCase { +class SiteLinkTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider constructorProvider diff --git a/DataModel/tests/phpunit/Snak/PropertyValueSnakTest.php b/DataModel/tests/phpunit/Snak/PropertyValueSnakTest.php index b82d3ac..4d30715 100644 --- a/DataModel/tests/phpunit/Snak/PropertyValueSnakTest.php +++ b/DataModel/tests/phpunit/Snak/PropertyValueSnakTest.php @@ -81,35 +81,11 @@ $argLists[] = array( clone $property, new \Wikibase\EntityId( \Wikibase\Item::ENTITY_TYPE, 9001 ) ); - $libRegistry = new \Wikibase\LibRegistry( \Wikibase\Settings::singleton() ); - $property->setDataType( $libRegistry->getDataTypeFactory()->getType( 'commonsMedia' ) ); + $property->setDataTypeId( 'commonsMedia' ); $argLists[] = array( clone $property, new \DataValues\StringValue( 'https://commons.wikimedia.org/wiki/Wikidata' ) ); return $argLists; - } - - /** - * @dataProvider newFromPropertyValueProvider - */ - public function testNewFromPropertyValue( \Wikibase\Property $property, \DataValues\DataValue $dataValue ) { - if ( !class_exists( '\Wikibase\PropertyContent' ) ) { - $this->markTestSkipped( 'PropertyContent class not found' ); - } - - // We need to make sure the property exists since otherwise - // we cannot obtain it based on id in the method being tested. - $content = \Wikibase\PropertyContent::newFromProperty( $property ); - $content->save(); - - $instance = PropertyValueSnak::newFromPropertyValue( - $property->getId(), - $dataValue->getArrayValue() - ); - - $this->assertInstanceOf( '\Wikibase\PropertyValueSnak', $instance ); - $this->assertTrue( $instance->getDataValue()->equals( $dataValue ) ); - $this->assertEquals( $property->getId(), $instance->getPropertyId() ); } } diff --git a/DataModel/tests/phpunit/Snak/SnakListTest.php b/DataModel/tests/phpunit/Snak/SnakListTest.php index e62dae3..1742d34 100644 --- a/DataModel/tests/phpunit/Snak/SnakListTest.php +++ b/DataModel/tests/phpunit/Snak/SnakListTest.php @@ -3,6 +3,8 @@ namespace Wikibase\Test; use DataValues\StringValue; +use Wikibase\EntityId; +use Wikibase\Property; use Wikibase\PropertyNoValueSnak; use Wikibase\PropertyValueSnak; use Wikibase\Snak; @@ -52,20 +54,20 @@ * @see GenericArrayObjectTest::elementInstancesProvider */ public function elementInstancesProvider() { - $id42 = new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 42 ); + $id42 = new EntityId( Property::ENTITY_TYPE, 42 ); - $instances = array( - new PropertyNoValueSnak( $id42 ), - new PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 9001 ) ), - new PropertyValueSnak( $id42, new StringValue( 'a' ) ), - ); + $argLists = array(); - return $this->arrayWrap( $this->arrayWrap( $instances ) ); + $argLists[] = array( array( new PropertyNoValueSnak( $id42 ) ) ); + $argLists[] = array( array( new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 9001 ) ) ) ); + $argLists[] = array( array( new PropertyValueSnak( $id42, new StringValue( 'a' ) ) ) ); + + return $argLists; } public function constructorProvider() { - $id42 = new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 42 ); - $id9001 = new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 9001 ); + $id42 = new EntityId( Property::ENTITY_TYPE, 42 ); + $id9001 = new EntityId( Property::ENTITY_TYPE, 9001 ); return array( array(), @@ -130,7 +132,7 @@ $this->assertEquals( --$elementCount, $array->count() ); } - $element = new PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 42 ) ); + $element = new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 42 ) ); $array->removeSnak( $element ); $array->removeSnakHash( $element->getHash() ); diff --git a/DataModel/tests/phpunit/Snak/SnakObjectTest.php b/DataModel/tests/phpunit/Snak/SnakObjectTest.php index 4c7573e..0880655 100644 --- a/DataModel/tests/phpunit/Snak/SnakObjectTest.php +++ b/DataModel/tests/phpunit/Snak/SnakObjectTest.php @@ -35,7 +35,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -abstract class SnakObjectTest extends \MediaWikiTestCase { +abstract class SnakObjectTest extends \PHPUnit_Framework_TestCase { /** * Returns the name of the concrete class tested by this test. diff --git a/DataModel/tests/phpunit/Snak/SnakTest.php b/DataModel/tests/phpunit/Snak/SnakTest.php index 421ebeb..d9ef963 100644 --- a/DataModel/tests/phpunit/Snak/SnakTest.php +++ b/DataModel/tests/phpunit/Snak/SnakTest.php @@ -35,7 +35,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class SnakTest extends \MediaWikiTestCase { +class SnakTest extends \PHPUnit_Framework_TestCase { public function snakProvider() { $snaks = array(); @@ -56,7 +56,13 @@ $snaks[] = new \Wikibase\PropertyValueSnak( $id42, $value ); } - return $this->arrayWrap( $snaks ); + $argLists = array(); + + foreach ( $snaks as $snak ) { + $argLists[] = array( $snak ); + } + + return $argLists; } /** diff --git a/DataModel/tests/phpunit/hasharray/HashArrayTest.php b/DataModel/tests/phpunit/hasharray/HashArrayTest.php index 0a61ebd..c8171c6 100644 --- a/DataModel/tests/phpunit/hasharray/HashArrayTest.php +++ b/DataModel/tests/phpunit/hasharray/HashArrayTest.php @@ -35,7 +35,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -abstract class HashArrayTest extends \MediaWikiTestCase { +abstract class HashArrayTest extends \PHPUnit_Framework_TestCase { public abstract function constructorProvider(); @@ -127,6 +127,15 @@ $this->assertFalse( $array->equals( 42 ) ); } + protected function arrayWrap( array $elements ) { + return array_map( + function ( $element ) { + return array( $element ); + }, + $elements + ); + } + } class MutableHashable implements Hashable { diff --git a/DataModel/tests/testLoader.php b/DataModel/tests/testLoader.php new file mode 100644 index 0000000..ea1669e --- /dev/null +++ b/DataModel/tests/testLoader.php @@ -0,0 +1,30 @@ +<?php + +/** + * Test class autoloader for the Wikibase DataModel component. + * + * @since 0.1 + * + * @file + * @ingroup DataModel + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ + +spl_autoload_register( function ( $className ) { + $testClasses = array( + 'Wikibase\Test\ClaimTest' => 'Claim/ClaimTest.php', + 'Wikibase\Test\EntityTest' => 'Entity/EntityTest.php', + 'Wikibase\Test\TestItems' => 'Entity/TestItems.php', + 'Wikibase\Test\SnakObjectTest' => 'Snak/SnakObjectTest.php', + + 'Wikibase\Test\HashArrayTest' => 'hasharray/HashArrayTest.php', + 'Wikibase\Test\HashArrayElement' => 'hasharray/HashArrayElement.php', + 'Wikibase\Test\EntityDiffOldTest' => 'EntityDiffOldTest.php', + ); + + if ( array_key_exists( $className, $testClasses ) ) { + include_once __DIR__ . '/phpunit/' . $testClasses[$className]; + } +} ); diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php index 0e72ba6..302096b 100644 --- a/lib/WikibaseLib.classes.php +++ b/lib/WikibaseLib.classes.php @@ -34,7 +34,6 @@ // includes 'Wikibase\Arrayalizer' => 'includes/Arrayalizer.php', - 'Wikibase\ByPropertyIdArray' => 'includes/ByPropertyIdArray.php', 'Wikibase\ChangeNotifier' => 'includes/ChangeNotifier.php', 'Wikibase\ChangeNotificationJob' => 'includes/ChangeNotificationJob.php', 'Wikibase\ChangesTable' => 'includes/ChangesTable.php', @@ -74,10 +73,8 @@ 'Wikibase\ClaimDifferenceVisualizer' => 'includes/ClaimDifferenceVisualizer.php', - 'Wikibase\EntityDiff' => 'includes/EntityDiff.php', 'Wikibase\EntityDiffVisualizer' => 'includes/EntityDiffVisualizer.php', 'Wikibase\EntityFactory' => 'includes/EntityFactory.php', - 'Wikibase\ItemDiff' => 'includes/ItemDiff.php', // includes/formatters 'Wikibase\Lib\EntityIdFormatter' => 'includes/formatters/EntityIdFormatter.php', @@ -145,7 +142,6 @@ 'Wikibase\Test\EntityChangeTest' => 'tests/phpunit/changes/EntityChangeTest.php', 'Wikibase\Test\TestChanges' => 'tests/phpunit/changes/TestChanges.php', - 'Wikibase\Test\EntityDiffOldTest' => 'tests/phpunit/entity/EntityDiffOldTest.php', 'Wikibase\Test\EntityRefreshTest' => 'tests/phpunit/changes/EntityRefreshTest.php', 'Wikibase\Test\SerializerBaseTest' => 'tests/phpunit/serializers/SerializerBaseTest.php', 'Wikibase\Test\EntitySerializerBaseTest' => 'tests/phpunit/serializers/EntitySerializerBaseTest.php', diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php index 643bbf4..bcca45b 100644 --- a/lib/WikibaseLib.hooks.php +++ b/lib/WikibaseLib.hooks.php @@ -36,13 +36,10 @@ 'claim/ClaimDifferenceVisualizer', 'claim/ClaimDiffer', - 'entity/EntityDiff', 'entity/EntityFactory', 'formatters/EntityIdFormatter', 'formatters/EntityIdLabelFormatter', - - 'item/ItemDiff', 'parsers/EntityIdParser', @@ -70,7 +67,6 @@ 'util/HttpAcceptParser', 'util/HttpAcceptNegotiator', - 'ByPropertyIdArray', 'ChangesTable', 'ClaimDifference', 'ClaimGuidValidator', -- To view, visit https://gerrit.wikimedia.org/r/65674 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I44397a6b6384cb0210e7a08a552bea90515e4716 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits