Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Have DescriptionMatchFinder return instances of EntityId rather 
then internal ids
......................................................................

Have DescriptionMatchFinder return instances of EntityId rather then internal 
ids

Change-Id: Ibc104d0545e12ac5f6dfe31014056087db278e44
---
M src/SQLStore/Engine/DescriptionMatchFinder.php
M src/SQLStore/Factory.php
M tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
M tests/integration/SQLStore/WritingIntegrationTest.php
M tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
5 files changed, 45 insertions(+), 21 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQueryEngine 
refs/changes/45/74645/1

diff --git a/src/SQLStore/Engine/DescriptionMatchFinder.php 
b/src/SQLStore/Engine/DescriptionMatchFinder.php
index a61a48e..2b6224f 100644
--- a/src/SQLStore/Engine/DescriptionMatchFinder.php
+++ b/src/SQLStore/Engine/DescriptionMatchFinder.php
@@ -14,6 +14,7 @@
 use Wikibase\QueryEngine\QueryNotSupportedException;
 use Wikibase\QueryEngine\SQLStore\DataValueHandler;
 use Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder;
+use Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter;
 use Wikibase\QueryEngine\SQLStore\Schema;
 use Wikibase\SnakRole;
 
@@ -34,22 +35,24 @@
        protected $schema;
        protected $propertyDataValueTypeLookup;
        protected $idFinder;
+       protected $idInterpreter;
 
        public function __construct( QueryInterface $queryInterface,
                        Schema $schema,
                        PropertyDataValueTypeLookup 
$propertyDataValueTypeLookup,
-                       InternalEntityIdFinder $idFinder ) {
+                       InternalEntityIdFinder $idFinder,
+                       InternalEntityIdInterpreter $idInterpreter ) {
+
                $this->queryInterface = $queryInterface;
                $this->schema = $schema;
                $this->propertyDataValueTypeLookup = 
$propertyDataValueTypeLookup;
                $this->idFinder = $idFinder;
+               $this->idInterpreter = $idInterpreter;
        }
 
        /**
         * Finds all entities that match the selection criteria.
         * The matching entities are returned as an array of internal entity 
ids.
-        *
-        * TODO: return array of EntityId
         *
         * @since 0.1
         *
@@ -95,7 +98,7 @@
                $entityIds = array();
 
                foreach ( $selectionResult as $resultRow ) {
-                       $entityIds[] = (int)$resultRow->subject_id;
+                       $entityIds[] = 
$this->idInterpreter->getExternalIdForEntity( (int)$resultRow->subject_id );
                }
 
                return $entityIds;
diff --git a/src/SQLStore/Factory.php b/src/SQLStore/Factory.php
index 20e2522..64cfa61 100644
--- a/src/SQLStore/Factory.php
+++ b/src/SQLStore/Factory.php
@@ -141,6 +141,13 @@
                return new EntityIdTransformer( 
$this->config->getEntityTypeMap() );
        }
 
+       /**
+        * @return InternalEntityIdInterpreter
+        */
+       protected function getInternalEntityIdInterpreter() {
+               return new EntityIdTransformer( 
$this->config->getEntityTypeMap() );
+       }
+
        public function newWriter() {
                return new Writer(
                        $this->newEntityInserter(),
@@ -157,7 +164,8 @@
                        $this->queryInterface,
                        $this->getSchema(),
                        $this->config->getPropertyDataValueTypeLookup(),
-                       $this->getInternalEntityIdFinder()
+                       $this->getInternalEntityIdFinder(),
+                       $this->getInternalEntityIdInterpreter()
                );
        }
 
diff --git 
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php 
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
index fb763ff..a35bd9e 100644
--- 
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
+++ 
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
@@ -11,6 +11,7 @@
 use Wikibase\Database\MediaWikiQueryInterface;
 use Wikibase\Database\MessageReporter;
 use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
+use Wikibase\Database\MWDB\ExtendedSQLiteAbstraction;
 use Wikibase\Database\TableDefinition;
 use Wikibase\EntityId;
 use Wikibase\Item;
@@ -42,8 +43,8 @@
        protected $store;
 
        public function setUp() {
-               if ( !defined( 'MEDIAWIKI' ) || wfGetDB( DB_MASTER )->getType() 
!== 'mysql' ) {
-                       $this->markTestSkipped( 'Can only run 
DescriptionMatchFinderIntegrationTest on MySQL' );
+               if ( !defined( 'MEDIAWIKI' ) || wfGetDB( DB_MASTER )->getType() 
!== 'sqlite' ) {
+                       $this->markTestSkipped( 'Can only run 
DescriptionMatchFinderIntegrationTest on SQLite' );
                }
 
                parent::setUp();
@@ -64,9 +65,10 @@
        protected function newStore() {
                $dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER 
);
 
+               // TODO: use factory in DB component
                $queryInterface = new MediaWikiQueryInterface(
                        $dbConnectionProvider,
-                       new ExtendedMySQLAbstraction( $dbConnectionProvider )
+                       new ExtendedSQLiteAbstraction( $dbConnectionProvider )
                );
 
                $config = new StoreConfig(
@@ -158,7 +160,7 @@
                $matchingEntityIds = $matchFinder->getMatchingEntities( 
$description, $queryOptions );
 
                $this->assertInternalType( 'array', $matchingEntityIds );
-               $this->assertContainsOnly( 'int', $matchingEntityIds );
+               $this->assertContainsOnlyInstancesOf( 'Wikibase\EntityId', 
$matchingEntityIds );
 
                $this->assertEquals( $expectedIds, $matchingEntityIds );
        }
@@ -171,7 +173,7 @@
                                new EntityId( 'property', 42 ),
                                new ValueDescription( new NumberValue( 1337 ) )
                        ),
-                       array( 11120, 11150 )
+                       array( new EntityId( 'item', 1112 ), new EntityId( 
'item', 1115 ) )
                );
 
                $argLists[] = array(
@@ -187,7 +189,7 @@
                                new EntityId( 'property', 43 ),
                                new ValueDescription( new NumberValue( 1337 ) )
                        ),
-                       array( 11130 )
+                       array( new EntityId( 'item', 1113 ) )
                );
 
                $argLists[] = array(
@@ -195,7 +197,7 @@
                                new EntityId( 'property', 42 ),
                                new ValueDescription( new NumberValue( 72010 ) )
                        ),
-                       array( 11140 )
+                       array( new EntityId( 'item', 1114 ) )
                );
 
                return $argLists;
diff --git a/tests/integration/SQLStore/WritingIntegrationTest.php 
b/tests/integration/SQLStore/WritingIntegrationTest.php
index 203340e..ca67454 100644
--- a/tests/integration/SQLStore/WritingIntegrationTest.php
+++ b/tests/integration/SQLStore/WritingIntegrationTest.php
@@ -13,6 +13,7 @@
 use Wikibase\Database\MediaWikiQueryInterface;
 use Wikibase\Database\MessageReporter;
 use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
+use Wikibase\Database\MWDB\ExtendedSQLiteAbstraction;
 use Wikibase\Database\TableDefinition;
 use Wikibase\EntityId;
 use Wikibase\Item;
@@ -47,8 +48,8 @@
        protected $store;
 
        public function setUp() {
-               if ( !defined( 'MEDIAWIKI' ) || wfGetDB( DB_MASTER )->getType() 
!== 'mysql' ) {
-                       $this->markTestSkipped( 'Can only run 
DescriptionMatchFinderIntegrationTest on MySQL' );
+               if ( !defined( 'MEDIAWIKI' ) || wfGetDB( DB_MASTER )->getType() 
!== 'sqlite' ) {
+                       $this->markTestSkipped( 'Can only run 
DescriptionMatchFinderIntegrationTest on SQLite' );
                }
 
                parent::setUp();
@@ -67,9 +68,10 @@
        protected function newStore() {
                $dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER 
);
 
+               // TODO: use factory in DB component
                $queryInterface = new MediaWikiQueryInterface(
                        $dbConnectionProvider,
-                       new ExtendedMySQLAbstraction( $dbConnectionProvider )
+                       new ExtendedSQLiteAbstraction( $dbConnectionProvider )
                );
 
                $config = new StoreConfig(
@@ -117,7 +119,7 @@
                );
 
                $this->assertEquals(
-                       array( 88880 ),
+                       array( new EntityId( 'item', 8888 ) ),
                        $this->findMatchingEntities( $propertyDescription )
                );
 
@@ -169,7 +171,7 @@
                );
 
                $this->assertEquals(
-                       array( 44440 ),
+                       array( new EntityId( 'item', 4444 ) ),
                        $this->findMatchingEntities( $propertyDescription )
                );
 
diff --git a/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php 
b/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
index 311c2a7..3c0f32a 100644
--- a/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
+++ b/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
@@ -41,7 +41,8 @@
                        $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\Schema' )
                                ->disableOriginalConstructor()->getMock(),
                        $this->getMock( 
'Wikibase\QueryEngine\PropertyDataValueTypeLookup' ),
-                       $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' )
+                       $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' ),
+                       $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter' )
                );
        }
 
@@ -89,18 +90,26 @@
 
                $idTransformer = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdFinder' );
 
+               $idInterpreter = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\InternalEntityIdInterpreter' );
+
+               $idInterpreter->expects( $this->atLeastOnce() )
+                       ->method( 'getExternalIdForEntity' )
+                       ->with( $this->equalTo( 10 ) )
+                       ->will( $this->returnValue( new EntityId( 'item', 1 ) ) 
);
+
                $matchFinder = new DescriptionMatchFinder(
                        $queryEngine,
                        $schema,
                        $dvTypeLookup,
-                       $idTransformer
+                       $idTransformer,
+                       $idInterpreter
                );
 
                $matchingInternalIds = $matchFinder->findMatchingEntities( 
$description, $queryOptions );
 
                $this->assertInternalType( 'array', $matchingInternalIds );
-               $this->assertContainsOnly( 'int', $matchingInternalIds );
-               $this->assertEquals( array( 10 ), $matchingInternalIds );
+               $this->assertContainsOnlyInstancesOf( 'Wikibase\EntityId', 
$matchingInternalIds );
+               $this->assertEquals( array( new EntityId( 'item', 1 ) ), 
$matchingInternalIds );
        }
 
        public function testFindMatchingEntitiesWithInvalidPropertyId() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc104d0545e12ac5f6dfe31014056087db278e44
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQueryEngine
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to