Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/217243
Change subject: Phase out deprecated EntityFactory::singleton
......................................................................
Phase out deprecated EntityFactory::singleton
This patch:
* Makes EntityFactoryTest completely independent from other components
and classes. This also means I'm replacing the constants with strings
on purpose.
* Implements a simple "make new entity" method in JsonDumpGeneratorTest
that does not need a factory.
* Replaces singleton with WikibaseRepo factory method in the other two
cases.
Change-Id: I4ec8bd9158f7d6dc25e4cc70c074b8cbb79b110a
---
M lib/includes/EntityFactory.php
M lib/tests/phpunit/entity/EntityFactoryTest.php
M repo/tests/phpunit/includes/Dumpers/JsonDumpGeneratorTest.php
M repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php
M repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
5 files changed, 29 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/43/217243/1
diff --git a/lib/includes/EntityFactory.php b/lib/includes/EntityFactory.php
index 1b624fe..78e79ea 100644
--- a/lib/includes/EntityFactory.php
+++ b/lib/includes/EntityFactory.php
@@ -5,8 +5,6 @@
use MWException;
use OutOfBoundsException;
use Wikibase\DataModel\Entity\Entity;
-use Wikibase\DataModel\Entity\Item;
-use Wikibase\DataModel\Entity\Property;
/**
* Factory for Entity objects.
@@ -35,28 +33,6 @@
*/
public function __construct( array $typeToClass ) {
$this->typeMap = $typeToClass;
- }
-
- /**
- * @since 0.2
- *
- * @deprecated Use WikibaseRepo::getEntityFactory() resp.
WikibaseClient::getEntityFactory()
- *
- * @return EntityFactory
- */
- public static function singleton() {
- static $instance = false;
-
- if ( $instance === false ) {
- $typeToClass = array(
- Item::ENTITY_TYPE =>
'Wikibase\DataModel\Entity\Item',
- Property::ENTITY_TYPE =>
'Wikibase\DataModel\Entity\Property',
- );
-
- $instance = new static( $typeToClass );
- }
-
- return $instance;
}
/**
diff --git a/lib/tests/phpunit/entity/EntityFactoryTest.php
b/lib/tests/phpunit/entity/EntityFactoryTest.php
index 77b223f..c8f783e 100644
--- a/lib/tests/phpunit/entity/EntityFactoryTest.php
+++ b/lib/tests/phpunit/entity/EntityFactoryTest.php
@@ -2,8 +2,6 @@
namespace Wikibase\Test;
-use Wikibase\DataModel\Entity\Item;
-use Wikibase\DataModel\Entity\Property;
use Wikibase\EntityFactory;
/**
@@ -19,15 +17,18 @@
class EntityFactoryTest extends \MediaWikiTestCase {
private function getEntityFactory() {
- return EntityFactory::singleton();
+ return new EntityFactory( array(
+ 'item' => 'Wikibase\DataModel\Entity\Item',
+ 'property' => 'Wikibase\DataModel\Entity\Property',
+ ) );
}
public function testGetEntityTypes() {
$types = $this->getEntityFactory()->getEntityTypes();
$this->assertInternalType( 'array', $types );
- $this->assertTrue( in_array( Item::ENTITY_TYPE, $types ), "must
contain item type" );
- $this->assertTrue( in_array( Property::ENTITY_TYPE, $types ),
"must contain property type" );
+ $this->assertTrue( in_array( 'item', $types ), 'must contain
item type' );
+ $this->assertTrue( in_array( 'property', $types ), 'must
contain property type' );
}
public function provideIsEntityType() {
@@ -55,8 +56,8 @@
public function provideNewEmpty() {
return array(
- array( Item::ENTITY_TYPE,
'Wikibase\DataModel\Entity\Item' ),
- array( Property::ENTITY_TYPE,
'Wikibase\DataModel\Entity\Property' ),
+ array( 'item', 'Wikibase\DataModel\Entity\Item' ),
+ array( 'property', 'Wikibase\DataModel\Entity\Property'
),
);
}
@@ -67,7 +68,7 @@
$entity = $this->getEntityFactory()->newEmpty( $type );
$this->assertInstanceOf( $class, $entity );
- $this->assertTrue( $entity->isEmpty(), "should be empty" );
+ $this->assertTrue( $entity->isEmpty(), 'should be empty' );
}
}
diff --git a/repo/tests/phpunit/includes/Dumpers/JsonDumpGeneratorTest.php
b/repo/tests/phpunit/includes/Dumpers/JsonDumpGeneratorTest.php
index 7e51123..14946a0 100644
--- a/repo/tests/phpunit/includes/Dumpers/JsonDumpGeneratorTest.php
+++ b/repo/tests/phpunit/includes/Dumpers/JsonDumpGeneratorTest.php
@@ -2,6 +2,7 @@
namespace Wikibase\Test\Dumpers;
+use InvalidArgumentException;
use MWContentSerializationException;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\DataModel\Entity\Entity;
@@ -11,7 +12,6 @@
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\Dumpers\JsonDumpGenerator;
-use Wikibase\EntityFactory;
use Wikibase\Lib\Serializers\DispatchingEntitySerializer;
use Wikibase\Lib\Serializers\SerializationOptions;
use Wikibase\Lib\Serializers\SerializerFactory;
@@ -70,21 +70,21 @@
/**
* @param EntityId $id
*
- * @return Entity
+ * @throws InvalidArgumentException
+ * @return Item|Property
*/
protected function makeEntity( EntityId $id ) {
- $entity = EntityFactory::singleton()->newEmpty(
$id->getEntityType() );
- $entity->setId( $id );
- $entity->setLabel( 'en', 'label:' . $id->getSerialization() );
-
- if ( $entity instanceof Property ) {
- $entity->setDataTypeId( 'wibblywobbly' );
- }
-
- if ( $entity instanceof Item ) {
+ if ( $id instanceof ItemId ) {
+ $entity = new Item( $id );
$entity->getSiteLinkList()->addNewSiteLink( 'test',
'Foo' );
+ } elseif ( $id instanceof PropertyId ) {
+ $entity = new Property( $id, null, 'wibblywobbly' );
+ } else {
+ throw new InvalidArgumentException( 'Unsupported entity
type ' . $id->getEntityType() );
}
+ $entity->setLabel( 'en', 'label:' . $id->getSerialization() );
+
return $entity;
}
diff --git a/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php
b/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php
index 3e91107..e87d84c 100644
--- a/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php
+++ b/repo/tests/phpunit/includes/api/ApiHelperFactoryTest.php
@@ -4,7 +4,7 @@
use Language;
use Wikibase\Api\ApiHelperFactory;
-use Wikibase\EntityFactory;
+use Wikibase\Repo\WikibaseRepo;
/**
* @covers Wikibase\Api\ApiHelperFactory
@@ -22,12 +22,13 @@
$titleLookup = $this->getMock(
'Wikibase\Lib\Store\EntityTitleLookup' );
$exceptionLocalizer = $this->getMock(
'Wikibase\Lib\Localizer\ExceptionLocalizer' );
$dataTypeLookup = $this->getMock(
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
+ $entityFactory =
WikibaseRepo::getDefaultInstance()->getEntityFactory();
return new ApiHelperFactory(
$titleLookup,
$exceptionLocalizer,
$dataTypeLookup,
- EntityFactory::singleton()
+ $entityFactory
);
}
diff --git a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
index 1e5a5b8..cd4a920 100644
--- a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
@@ -11,13 +11,13 @@
use Title;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\EntityFactory;
use Wikibase\Lib\Serializers\SerializationOptions;
use Wikibase\Lib\Serializers\SerializerFactory;
use Wikibase\Repo\LinkedData\EntityDataRequestHandler;
use Wikibase\Repo\LinkedData\EntityDataSerializationService;
use Wikibase\Repo\LinkedData\EntityDataUriManager;
use Wikibase\Repo\Specials\SpecialEntityData;
+use Wikibase\Repo\WikibaseRepo;
/**
* @covers Wikibase\Repo\Specials\SpecialEntityData
@@ -59,18 +59,17 @@
return Title::newFromText( $id->getEntityType()
. ':' . $id->getSerialization() );
} ) );
- $idParser = new BasicEntityIdParser();
-
$dataTypeLookup = $this->getMock(
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
$dataTypeLookup->expects( $this->any() )
->method( 'getDataTypeIdForProperty' )
->will( $this->returnValue( 'string' ) );
- $serializationOptions = new SerializationOptions();
+ $entityFactory =
WikibaseRepo::getDefaultInstance()->getEntityFactory();
+
$serializerFactory = new SerializerFactory(
- $serializationOptions,
+ new SerializationOptions(),
$dataTypeLookup,
- EntityFactory::singleton()
+ $entityFactory
);
$serializationService = new EntityDataSerializationService(
@@ -104,7 +103,7 @@
return new EntityDataRequestHandler(
$uriManager,
$titleLookup,
- $idParser,
+ new BasicEntityIdParser(),
$mockRepository,
$mockRepository,
$serializationService,
--
To view, visit https://gerrit.wikimedia.org/r/217243
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4ec8bd9158f7d6dc25e4cc70c074b8cbb79b110a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits