Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/188354

Change subject: Avoid calling deprecated EntityFactory::singleton()
......................................................................

Avoid calling deprecated EntityFactory::singleton()

This reduces the number of calls to the deprecated method, but does
not remove all because I think this is not worth our time, at the
moment.

Change-Id: I537d6bf245c5ece58a83733d19ce9b29d5f9b3f6
---
M lib/tests/phpunit/entity/EntityFactoryTest.php
M repo/includes/api/EditEntity.php
M repo/includes/api/SearchEntities.php
M repo/includes/specials/SpecialEntityData.php
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
5 files changed, 23 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/54/188354/1

diff --git a/lib/tests/phpunit/entity/EntityFactoryTest.php 
b/lib/tests/phpunit/entity/EntityFactoryTest.php
index 374be06..77b223f 100644
--- a/lib/tests/phpunit/entity/EntityFactoryTest.php
+++ b/lib/tests/phpunit/entity/EntityFactoryTest.php
@@ -18,20 +18,22 @@
  */
 class EntityFactoryTest extends \MediaWikiTestCase {
 
-       public function testGetEntityTypes() {
-               $types = EntityFactory::singleton()->getEntityTypes();
-               $this->assertInternalType( 'array', $types );
+       private function getEntityFactory() {
+               return EntityFactory::singleton();
+       }
 
+       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" );
        }
 
        public function provideIsEntityType() {
-               $types = EntityFactory::singleton()->getEntityTypes();
-
                $tests = array();
 
-               foreach ( $types as $type ) {
+               foreach ( $this->getEntityFactory()->getEntityTypes() as $type 
) {
                        $tests[] = array ( $type, true );
                }
 
@@ -42,9 +44,13 @@
 
        /**
         * @dataProvider provideIsEntityType
+        * @param string $type
+        * @param bool $expected
         */
        public function testIsEntityType( $type, $expected ) {
-               $this->assertEquals( $expected, 
EntityFactory::singleton()->isEntityType( $type ) );
+               $entityFactory = $this->getEntityFactory();
+
+               $this->assertEquals( $expected, $entityFactory->isEntityType( 
$type ) );
        }
 
        public function provideNewEmpty() {
@@ -58,7 +64,7 @@
         * @dataProvider provideNewEmpty
         */
        public function testNewEmpty( $type, $class ) {
-               $entity = EntityFactory::singleton()->newEmpty( $type );
+               $entity = $this->getEntityFactory()->newEmpty( $type );
 
                $this->assertInstanceOf( $class, $entity );
                $this->assertTrue( $entity->isEmpty(), "should be empty" );
diff --git a/repo/includes/api/EditEntity.php b/repo/includes/api/EditEntity.php
index 0851268..0cf2ec5 100644
--- a/repo/includes/api/EditEntity.php
+++ b/repo/includes/api/EditEntity.php
@@ -23,7 +23,6 @@
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\Property;
 use Wikibase\DataModel\Term\FingerprintProvider;
-use Wikibase\EntityFactory;
 use Wikibase\Lib\Serializers\SerializerFactory;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Repo\WikibaseRepo;
@@ -117,7 +116,7 @@
        protected function createEntity( array $params ) {
                $type = $params['new'];
                $this->flags |= EDIT_NEW;
-               $entityFactory = EntityFactory::singleton();
+               $entityFactory = 
WikibaseRepo::getDefaultInstance()->getEntityFactory();
 
                try {
                        return $entityFactory->newEmpty( $type );
diff --git a/repo/includes/api/SearchEntities.php 
b/repo/includes/api/SearchEntities.php
index f976644..45e3d84 100644
--- a/repo/includes/api/SearchEntities.php
+++ b/repo/includes/api/SearchEntities.php
@@ -7,7 +7,6 @@
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\DataModel\Entity\EntityIdParsingException;
-use Wikibase\EntityFactory;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Term;
@@ -323,6 +322,8 @@
         * @see ApiBase::getAllowedParams
         */
        protected function getAllowedParams() {
+               $entityFactory = 
WikibaseRepo::getDefaultInstance()->getEntityFactory();
+
                return array(
                        'search' => array(
                                ApiBase::PARAM_TYPE => 'string',
@@ -333,7 +334,7 @@
                                ApiBase::PARAM_REQUIRED => true,
                        ),
                        'type' => array(
-                               ApiBase::PARAM_TYPE => 
EntityFactory::singleton()->getEntityTypes(),
+                               ApiBase::PARAM_TYPE => 
$entityFactory->getEntityTypes(),
                                ApiBase::PARAM_DFLT => 'item',
                        ),
                        'limit' => array(
diff --git a/repo/includes/specials/SpecialEntityData.php 
b/repo/includes/specials/SpecialEntityData.php
index 6d0523c..c59af1b 100644
--- a/repo/includes/specials/SpecialEntityData.php
+++ b/repo/includes/specials/SpecialEntityData.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Repo\Specials;
 
 use HttpError;
-use Wikibase\EntityFactory;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\Serializers\SerializerFactory;
 use Wikibase\Repo\LinkedData\EntityDataRequestHandler;
@@ -83,7 +82,7 @@
                $serializerFactory = new SerializerFactory(
                        $serializationOptions,
                        $wikibaseRepo->getPropertyDataTypeLookup(),
-                       EntityFactory::singleton()
+                       $wikibaseRepo->getEntityFactory()
                );
 
                $serializationService = new EntityDataSerializationService(
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 389328b..6aa16cb 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -8,7 +8,6 @@
 use TestUser;
 use UsageException;
 use User;
-use Wikibase\EntityFactory;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
@@ -337,10 +336,12 @@
         * @param array $response
         */
        public function assertResultHasEntityType( $response ) {
+               $entityFactory = 
WikibaseRepo::getDefaultInstance()->getEntityFactory();
+
                if ( isset( $response['entity'] ) ) {
                        if ( isset( $response['entity']['type'] ) ) {
                                $this->assertTrue(
-                                       
EntityFactory::singleton()->isEntityType( $response['entity']['type'] ),
+                                       $entityFactory->isEntityType( 
$response['entity']['type'] ),
                                        "Missing valid 'type' in response."
                                );
                        }
@@ -348,7 +349,7 @@
                        foreach ( $response['entities'] as $entity ) {
                                if ( isset( $entity['type'] ) ) {
                                        $this->assertTrue(
-                                               
EntityFactory::singleton()->isEntityType( $entity['type'] ),
+                                               $entityFactory->isEntityType( 
$entity['type'] ),
                                                "Missing valid 'type' in 
response."
                                        );
                                }

-- 
To view, visit https://gerrit.wikimedia.org/r/188354
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I537d6bf245c5ece58a83733d19ce9b29d5f9b3f6
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

Reply via email to