Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/238119
Change subject: Remove old copy of RedirectResolvingEntityLookup and always use the new one ...................................................................... Remove old copy of RedirectResolvingEntityLookup and always use the new one Change-Id: I70613bb3e5e31c016adff67131050a22f11c481a --- M client/includes/store/sql/DirectSqlStore.php D lib/includes/store/RedirectResolvingEntityLookup.php D lib/tests/phpunit/store/RedirectResolvingEntityLookupTest.php M repo/includes/Dumpers/JsonDumpGenerator.php M repo/includes/Dumpers/RdfDumpGenerator.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/EntityModificationTestHelper.php 7 files changed, 5 insertions(+), 212 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/19/238119/1 diff --git a/client/includes/store/sql/DirectSqlStore.php b/client/includes/store/sql/DirectSqlStore.php index 0f78842..aad489e 100644 --- a/client/includes/store/sql/DirectSqlStore.php +++ b/client/includes/store/sql/DirectSqlStore.php @@ -19,11 +19,11 @@ use Wikibase\Client\WikibaseClient; use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Services\Lookup\EntityLookup; +use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\CachingEntityRevisionLookup; use Wikibase\Lib\Store\CachingSiteLinkLookup; use Wikibase\Lib\Store\EntityContentDataCodec; use Wikibase\Lib\Store\EntityRevisionLookup; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\RevisionBasedEntityLookup; use Wikibase\Lib\Store\SiteLinkLookup; use Wikibase\Lib\Store\SiteLinkTable; diff --git a/lib/includes/store/RedirectResolvingEntityLookup.php b/lib/includes/store/RedirectResolvingEntityLookup.php deleted file mode 100644 index e7da7d3..0000000 --- a/lib/includes/store/RedirectResolvingEntityLookup.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -namespace Wikibase\Lib\Store; - -use Wikibase\DataModel\Entity\EntityDocument; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Services\Lookup\EntityLookup; - -/** - * Implementation of EntityLookup that opaquely resolves one level - * of redirects when looking up entities. - * - * @since 0.5 - * - * @licence GNU GPL v2+ - * @author Daniel Kinzler - */ -class RedirectResolvingEntityLookup implements EntityLookup { - - /** - * An EntityRedirectResolvingDecorator wrapping and emulating a EntityLookup. - * - * @note This does not formally implement EntityLookup! - * - * @var EntityLookup - */ - protected $lookup; - - /** - * @param EntityLookup $lookup The lookup to use - */ - public function __construct( EntityLookup $lookup ) { - $this->lookup = new EntityRedirectResolvingDecorator( $lookup ); - } - - /** - * @see EntityLookup::getEntity - * - * If the given entity ID points to a redirect, that redirect is resolved and the - * target entity returned. - * - * Callers can detect the presence of a redirect by comparing the ID of the returned - * Entity with the request ID. - * - * @param EntityId $entityId - * - * @throws StorageException - * @return EntityDocument|null - */ - public function getEntity( EntityId $entityId ) { - return $this->lookup->getEntity( $entityId ); - } - - /** - * @see EntityLookup::hasEntity - * - * If the given entity ID points to a redirect, that redirect is resolved and the - * existence of the target entity is checked. - * - * @param EntityId $entityId - * - * @throws StorageException - * @return bool - */ - public function hasEntity( EntityId $entityId ) { - return $this->lookup->hasEntity( $entityId ); - } - -} diff --git a/lib/tests/phpunit/store/RedirectResolvingEntityLookupTest.php b/lib/tests/phpunit/store/RedirectResolvingEntityLookupTest.php deleted file mode 100644 index fde07c3..0000000 --- a/lib/tests/phpunit/store/RedirectResolvingEntityLookupTest.php +++ /dev/null @@ -1,138 +0,0 @@ -<?php - -namespace Wikibase\Lib\Test\Store; - -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\Item; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\DataModel\Services\Lookup\EntityLookup; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; -use Wikibase\Lib\Store\UnresolvedRedirectException; - -/** - * @covers Wikibase\Lib\Store\RedirectResolvingEntityLookup - * - * @group WikibaseLib - * @group Wikibase - * - * @licence GNU GPL v2+ - * @author Daniel Kinzler - */ -class RedirectResolvingEntityLookupTest extends \PHPUnit_Framework_TestCase { - - /** - * @param EntityId $id - * - * @return bool - */ - public function hasEntity( EntityId $id ) { - return $this->getEntity( $id ) !== null; - } - - /** - * @param EntityId $id - * - * @return null|Item - * @throws UnresolvedRedirectException - */ - public function getEntity( EntityId $id ) { - if ( $id->getSerialization() == 'Q11' ) { - throw new UnresolvedRedirectException( new ItemId( 'Q10' ) ); - } - - if ( $id->getSerialization() == 'Q12' ) { - throw new UnresolvedRedirectException( new ItemId( 'Q11' ) ); - } - - if ( $id->getSerialization() == 'Q21' ) { - throw new UnresolvedRedirectException( new ItemId( 'Q20' ) ); - } - - if ( $id->getSerialization() == 'Q10' ) { - return new Item( $id ); - } - - return null; - } - - /** - * @return EntityLookup - */ - public function getLookupDouble() { - $mock = $this->getMock( 'Wikibase\DataModel\Services\Lookup\EntityLookup' ); - - $mock->expects( $this->any() ) - ->method( 'getEntity' ) - ->will( $this->returnCallback( array( $this, 'getEntity' ) ) ); - - $mock->expects( $this->any() ) - ->method( 'hasEntity' ) - ->will( $this->returnCallback( array( $this, 'hasEntity' ) ) ); - - return $mock; - } - - public function getEntityProvider() { - return array( - 'no redirect' => array( new ItemId( 'Q10' ), new ItemId( 'Q10' ) ), - 'one redirect' => array( new ItemId( 'Q11' ), new ItemId( 'Q10' ) ), - ); - } - - /** - * @dataProvider getEntityProvider - */ - public function testGetEntity( EntityId $id, EntityId $expected ) { - $lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() ); - - $entity = $lookup->getEntity( $id ); - - if ( $expected === null ) { - $this->assertNull( $entity ); - } else { - $this->assertTrue( $expected->equals( $entity->getId() ) ); - } - } - - public function testGetEntity_missing() { - $lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() ); - - $id = new ItemId( 'Q7' ); // entity Q7 is not known - $this->assertNull( $lookup->getEntity( $id ) ); - } - - public function testGetEntity_brokenRedirect() { - $lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() ); - - $id = new ItemId( 'Q20' ); // Q20 is a broken redirect - $this->assertNull( $lookup->getEntity( $id ) ); - } - - public function testGetEntity_doubleRedirect() { - $lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() ); - - $id = new ItemId( 'Q12' ); // Q12 is a double redirect - - $this->setExpectedException( 'Wikibase\Lib\Store\UnresolvedRedirectException' ); - $lookup->getEntity( $id ); - } - - public function hasEntityProvider() { - return array( - 'unknown entity' => array( new ItemId( 'Q7' ), false ), - 'no redirect' => array( new ItemId( 'Q10' ), true ), - 'one redirect' => array( new ItemId( 'Q11' ), true ), - 'broken redirect' => array( new ItemId( 'Q21' ), false ), - ); - } - - /** - * @dataProvider hasEntityProvider - */ - public function testHasEntity( EntityId $id, $exists ) { - $lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() ); - - $this->assertEquals( $exists, $lookup->hasEntity( $id ) ); - } - -} diff --git a/repo/includes/Dumpers/JsonDumpGenerator.php b/repo/includes/Dumpers/JsonDumpGenerator.php index 4f6f48a..7b8d47d 100644 --- a/repo/includes/Dumpers/JsonDumpGenerator.php +++ b/repo/includes/Dumpers/JsonDumpGenerator.php @@ -11,9 +11,9 @@ use Wikibase\DataModel\Services\Entity\EntityPrefetcher; use Wikibase\DataModel\Services\Lookup\EntityLookup; use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; +use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Lib\Serialization\CallbackFactory; use Wikibase\Lib\Serialization\SerializationModifier; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\StorageException; use Wikibase\Lib\Store\UnresolvedRedirectException; diff --git a/repo/includes/Dumpers/RdfDumpGenerator.php b/repo/includes/Dumpers/RdfDumpGenerator.php index ab23dc2..57e8f71 100644 --- a/repo/includes/Dumpers/RdfDumpGenerator.php +++ b/repo/includes/Dumpers/RdfDumpGenerator.php @@ -9,8 +9,8 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Services\Entity\EntityPrefetcher; use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; +use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\EntityRevisionLookup; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\StorageException; use Wikibase\Lib\Store\UnresolvedRedirectException; use Wikibase\Rdf\HashDedupeBag; diff --git a/repo/includes/store/sql/SqlStore.php b/repo/includes/store/sql/SqlStore.php index 55e48df..ffd5778 100644 --- a/repo/includes/store/sql/SqlStore.php +++ b/repo/includes/store/sql/SqlStore.php @@ -12,6 +12,7 @@ use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Services\Lookup\EntityLookup; use Wikibase\DataModel\Services\Lookup\EntityRedirectLookup; +use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Lib\Reporting\ObservableMessageReporter; use Wikibase\Lib\Store\CachingEntityRevisionLookup; use Wikibase\Lib\Store\EntityContentDataCodec; @@ -21,7 +22,6 @@ use Wikibase\Lib\Store\EntityStoreWatcher; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\LabelConflictFinder; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\RevisionBasedEntityLookup; use Wikibase\Lib\Store\SiteLinkConflictLookup; use Wikibase\Lib\Store\SiteLinkStore; diff --git a/repo/tests/phpunit/includes/EntityModificationTestHelper.php b/repo/tests/phpunit/includes/EntityModificationTestHelper.php index 2c9adb6..df6250a 100644 --- a/repo/tests/phpunit/includes/EntityModificationTestHelper.php +++ b/repo/tests/phpunit/includes/EntityModificationTestHelper.php @@ -10,7 +10,7 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\EntityRedirect; use Wikibase\DataModel\Entity\EntityIdParser; -use Wikibase\Lib\Store\RedirectResolvingEntityLookup; +use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup; use Wikibase\Repo\WikibaseRepo; /** -- To view, visit https://gerrit.wikimedia.org/r/238119 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I70613bb3e5e31c016adff67131050a22f11c481a 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