[MediaWiki-commits] [Gerrit] Phase out deprecated EntityFactory::singleton - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. 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(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified 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
[MediaWiki-commits] [Gerrit] Phase out deprecated EntityFactory::singleton - change (mediawiki...Wikibase)
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