Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Work on store interface
......................................................................

Work on store interface

* Removed stubs that will not be implemented any time soon
* Simplified test cases
* Provide access to DescriptionMatchFinder functionality via the public 
interface

Change-Id: Iffea17e8728d1719d7d61597d86ba3d40bbd5820
---
M src/QueryEngine.php
M src/SQLStore/Engine/Engine.php
M src/SQLStore/Factory.php
M src/SQLStore/Store.php
M tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
M tests/integration/SQLStore/WritingIntegrationTest.php
D tests/phpunit/QueryEngineResultTest.php
D tests/phpunit/QueryEngineTest.php
D tests/phpunit/QueryStoreTest.php
M tests/phpunit/SQLStore/Engine/EngineTest.php
M tests/phpunit/SQLStore/StoreTest.php
11 files changed, 84 insertions(+), 365 deletions(-)


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

diff --git a/src/QueryEngine.php b/src/QueryEngine.php
index f0204d5..ad33281 100644
--- a/src/QueryEngine.php
+++ b/src/QueryEngine.php
@@ -2,27 +2,12 @@
 
 namespace Wikibase\QueryEngine;
 
-use Ask\Language\Query;
+use Ask\Language\Description\Description;
+use Ask\Language\Option\QueryOptions;
+use Wikibase\EntityId;
 
 /**
  * Interface for objects that can act as a query engine.
- *
- * A query engine can run a given Query and return the QueryResult for it.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
  *
  * @since 0.1
  *
@@ -37,10 +22,11 @@
        /**
         * @since 0.1
         *
-        * @param Query $query
+        * @param Description $description
+        * @param QueryOptions $options
         *
-        * @return QueryResult
+        * @return EntityId[]
         */
-       public function runQuery( Query $query );
+       public function getMatchingEntities( Description $description, 
QueryOptions $options );
 
 }
\ No newline at end of file
diff --git a/src/SQLStore/Engine/Engine.php b/src/SQLStore/Engine/Engine.php
index afb6ef9..0774e0d 100644
--- a/src/SQLStore/Engine/Engine.php
+++ b/src/SQLStore/Engine/Engine.php
@@ -9,24 +9,10 @@
 use Wikibase\QueryEngine\QueryEngine;
 use Wikibase\QueryEngine\QueryEngineResult;
 use Wikibase\QueryEngine\SQLStore\StoreConfig;
+use Wikibase\EntityId;
 
 /**
  * Simple query engine that works on top of the SQLStore.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
  *
  * @since 0.1
  *
@@ -38,42 +24,24 @@
  */
 class Engine implements QueryEngine {
 
-       /**
-        * @since 0.1
-        *
-        * @var StoreConfig
-        */
-       private $config;
+       private $matchFinder;
 
-       /**
-        * @since 0.1
-        *
-        * @var QueryInterface
-        */
-       private $queryInterface;
-
-       /**
-        * @since 0.1
-        *
-        * @param StoreConfig $storeConfig
-        * @param QueryInterface $queryInterface
-        */
-       public function __construct( StoreConfig $storeConfig, QueryInterface 
$queryInterface ) {
-               $this->config = $storeConfig;
-               $this->queryInterface = $queryInterface;
+       public function __construct( DescriptionMatchFinder $matchFinder ) {
+               $this->matchFinder = $matchFinder;
        }
 
        /**
-        * @see QueryEngine::runQuery
+        * @see QueryEngine::getMatchingEntities
         *
         * @since 0.1
         *
-        * @param Query $query
+        * @param Description $description
+        * @param QueryOptions $options
         *
-        * @return QueryEngineResult
+        * @return EntityId[]
         */
-       public function runQuery( Query $query ) {
-               // TODO
+       public function getMatchingEntities( Description $description, 
QueryOptions $options ) {
+               return $this->matchFinder->findMatchingEntities( $description, 
$options );
        }
 
 }
diff --git a/src/SQLStore/Factory.php b/src/SQLStore/Factory.php
index b1283ef..feaa290 100644
--- a/src/SQLStore/Factory.php
+++ b/src/SQLStore/Factory.php
@@ -170,7 +170,7 @@
        public function newDescriptionMatchFinder() {
                return new DescriptionMatchFinder(
                        $this->queryInterface,
-                       $this->schema,
+                       $this->getSchema(),
                        $this->config->getPropertyDataValueTypeLookup(),
                        $this->getInternalEntityIdFinder()
                );
diff --git a/src/SQLStore/Store.php b/src/SQLStore/Store.php
index 06036a9..ab3e389 100644
--- a/src/SQLStore/Store.php
+++ b/src/SQLStore/Store.php
@@ -89,8 +89,7 @@
         */
        public function getQueryEngine() {
                return new Engine(
-                       $this->config,
-                       $this->queryInterface
+                       $this->factory->newDescriptionMatchFinder()
                );
        }
 
@@ -122,15 +121,6 @@
                        $this->factory->getTableBuilder(),
                        $messageReporter
                );
-       }
-
-       /**
-        * TODO: figure out how to merge this into the QueryEngine interface
-        *
-        * @return DescriptionMatchFinder
-        */
-       public function getDescriptionMatchFinder() {
-               return $this->factory->newDescriptionMatchFinder();
        }
 
 }
diff --git 
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php 
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
index 5ccbcd7..0664b30 100644
--- 
a/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
+++ 
b/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
@@ -22,21 +22,6 @@
 use Wikibase\Statement;
 
 /**
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
  * @file
  * @since 0.1
  *
@@ -163,14 +148,14 @@
         * @dataProvider somePropertyProvider
         */
        public function testFindMatchingEntitiesWithSomeProperty( SomeProperty 
$description, array $expectedIds ) {
-               $matchFinder = $this->store->getDescriptionMatchFinder();
+               $matchFinder = $this->store->getQueryEngine();
 
                $queryOptions = new QueryOptions(
                        100,
                        0
                );
 
-               $matchingEntityIds = $matchFinder->findMatchingEntities( 
$description, $queryOptions );
+               $matchingEntityIds = $matchFinder->getMatchingEntities( 
$description, $queryOptions );
 
                $this->assertInternalType( 'array', $matchingEntityIds );
                $this->assertContainsOnly( 'int', $matchingEntityIds );
diff --git a/tests/integration/SQLStore/WritingIntegrationTest.php 
b/tests/integration/SQLStore/WritingIntegrationTest.php
index 5052eb2..17b8756 100644
--- a/tests/integration/SQLStore/WritingIntegrationTest.php
+++ b/tests/integration/SQLStore/WritingIntegrationTest.php
@@ -27,21 +27,6 @@
  * Tests the write operations (those exposed by 
Wikibase\QueryEngine\SQLStore\Writer)
  * by verifying the entities are found only when they should be.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
  * @file
  * @since 0.1
  *
@@ -149,14 +134,14 @@
         * @return int[]
         */
        protected function findMatchingEntities( Description $description ) {
-               $matchFinder = $this->store->getDescriptionMatchFinder();
+               $matchFinder = $this->store->getQueryEngine();
 
                $queryOptions = new QueryOptions(
                        100,
                        0
                );
 
-               return $matchFinder->findMatchingEntities( $description, 
$queryOptions );
+               return $matchFinder->getMatchingEntities( $description, 
$queryOptions );
        }
 
        public function testUpdateItem() {
diff --git a/tests/phpunit/QueryEngineResultTest.php 
b/tests/phpunit/QueryEngineResultTest.php
deleted file mode 100644
index 8a2b228..0000000
--- a/tests/phpunit/QueryEngineResultTest.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\Tests;
-
-use Wikibase\QueryEngine\QueryEngineResult;
-
-/**
- * @covers Wikibase\QueryEngine\QueryEngineResult
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @since 0.1
- *
- * @ingroup WikibaseQueryEngineTest
- *
- * @group Wikibase
- * @group WikibaseQueryEngine
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class QueryEngineResultTest extends \PHPUnit_Framework_TestCase {
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryEngineResult[]
-        */
-       protected function getInstances() {
-               $instances = array();
-
-               $instances[] = new QueryEngineResult();
-
-               return $instances;
-       }
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryEngineResult[][]
-        */
-       public function instanceProvider() {
-               $argLists = array();
-
-               foreach ( $this->getInstances() as $instance ) {
-                       $argLists[] = array( $instance );
-               }
-
-               return $argLists;
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryEngineResult $engineResult
-        */
-       public function testGetResultReturnType( QueryEngineResult 
$engineResult ) {
-               // TODO: switch type check to real object
-               $this->assertInstanceOf( 'Wikibase\QueryEngine\QueryResult', 
$engineResult->getQueryResult() );
-       }
-
-}
diff --git a/tests/phpunit/QueryEngineTest.php 
b/tests/phpunit/QueryEngineTest.php
deleted file mode 100644
index 2205bf6..0000000
--- a/tests/phpunit/QueryEngineTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\Tests;
-
-use Wikibase\QueryEngine\QueryEngine;
-
-/**
- * Base test class for Wikibase\QueryEngine\QueryEngine implementing classes.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @since 0.1
- *
- * @ingroup WikibaseQueryEngineTest
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-abstract class QueryEngineTest extends \PHPUnit_Framework_TestCase {
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryEngine[]
-        */
-       protected abstract function getInstances();
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryEngine[][]
-        */
-       public function instanceProvider() {
-               $argLists = array();
-
-               foreach ( $this->getInstances() as $instance ) {
-                       $argLists[] = array( $instance );
-               }
-
-               return $argLists;
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryEngine $queryEngine
-        */
-       public function testGetNameReturnType( QueryEngine $queryEngine ) {
-               // TODO
-
-//             $query = new \Ask\Language\Query(  );
-//             $this->assertInstanceOf( 
'Wikibase\QueryEngine\QueryEngineResult', $queryEngine->runQuery() );
-
-               $this->assertTrue( true );
-       }
-
-}
diff --git a/tests/phpunit/QueryStoreTest.php b/tests/phpunit/QueryStoreTest.php
deleted file mode 100644
index 21cb035..0000000
--- a/tests/phpunit/QueryStoreTest.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\Tests;
-
-use Wikibase\QueryEngine\QueryStore;
-
-/**
- * Base test class for Wikibase\QueryEngine\QueryStore implementing classes.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @since 0.1
- *
- * @ingroup WikibaseQueryEngineTest
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-abstract class QueryStoreTest extends \PHPUnit_Framework_TestCase {
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryStore[]
-        */
-       protected abstract function getInstances();
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryStore[][]
-        */
-       public function instanceProvider() {
-               $argLists = array();
-
-               foreach ( $this->getInstances() as $instance ) {
-                       $argLists[] = array( $instance );
-               }
-
-               return $argLists;
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryStore $queryStore
-        */
-       public function testGetNameReturnType( QueryStore $queryStore ) {
-               $this->assertInternalType( 'string', $queryStore->getName() );
-       }
-
-}
diff --git a/tests/phpunit/SQLStore/Engine/EngineTest.php 
b/tests/phpunit/SQLStore/Engine/EngineTest.php
index 6f4b0cf..2728dd6 100644
--- a/tests/phpunit/SQLStore/Engine/EngineTest.php
+++ b/tests/phpunit/SQLStore/Engine/EngineTest.php
@@ -2,59 +2,53 @@
 
 namespace Wikibase\QueryEngine\Tests\SQLStore;
 
-use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
-use Wikibase\Database\MediaWikiQueryInterface;
+use Ask\Language\Description\AnyValue;
+use Ask\Language\Option\QueryOptions;
+use Wikibase\EntityId;
 use Wikibase\QueryEngine\SQLStore\Engine\Engine;
-use Wikibase\QueryEngine\SQLStore\StoreConfig;
-use Wikibase\QueryEngine\Tests\QueryEngineTest;
 
 /**
  * @covers Wikibase\QueryEngine\SQLStore\Engine\Engine
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @since 0.1
  *
  * @ingroup WikibaseQueryEngineTest
- *
  * @group Wikibase
  * @group WikibaseQueryEngine
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-class EngineTest extends QueryEngineTest {
+class EngineTest extends \PHPUnit_Framework_TestCase {
 
-       /**
-        * @see QueryEngineTest::getInstances
-        */
-       protected function getInstances() {
-               $instances = array();
-
-               $connectionProvider = $this->getMock( 
'Wikibase\Database\DBConnectionProvider' );
-               $storeConfig = new StoreConfig( 'foo', 'bar', array() );
-               $queryInterface = new MediaWikiQueryInterface(
-                       $connectionProvider,
-                       new ExtendedMySQLAbstraction( $connectionProvider )
+       public function testGetMatchingEntities() {
+               $description = new AnyValue();
+               $options = new QueryOptions( 42, 10 );
+               $expectedIds = array(
+                       new EntityId( 'item', 1 ),
+                       new EntityId( 'property', 2 ),
+                       new EntityId( 'foo', 123 ),
                );
 
-               $instances[] = new Engine( $storeConfig, $queryInterface );
+               $matchFinder = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder' )
+                       ->disableOriginalConstructor()->getMock();
 
-               return $instances;
+               $matchFinder->expects( $this->once() )
+                       ->method( 'findMatchingEntities' )
+                       ->with(
+                               $this->equalTo( $description ),
+                               $this->equalTo( $options )
+                       )
+                       ->will( $this->returnValue( $expectedIds ) );
+
+               $engine = new Engine( $matchFinder );
+
+               $entityIds = $engine->getMatchingEntities( $description, 
$options );
+
+               $this->assertInternalType( 'array', $entityIds );
+               $this->assertContainsOnlyInstancesOf( 'Wikibase\EntityId', 
$entityIds );
+               $this->assertEquals( $expectedIds, $entityIds );
        }
 
 }
diff --git a/tests/phpunit/SQLStore/StoreTest.php 
b/tests/phpunit/SQLStore/StoreTest.php
index df0aa57..a1cd323 100644
--- a/tests/phpunit/SQLStore/StoreTest.php
+++ b/tests/phpunit/SQLStore/StoreTest.php
@@ -37,24 +37,48 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-class StoreTest extends QueryStoreTest {
+class StoreTest extends \PHPUnit_Framework_TestCase {
 
-       /**
-        * @see QueryStoreTest::getInstances
-        */
-       protected function getInstances() {
-               $instances = array();
-
+       protected function newInstance() {
                $connectionProvider = $this->getMock( 
'Wikibase\Repo\DBConnectionProvider' );
+
                $storeConfig = new StoreConfig( 'foo', 'bar', array() );
+
+               $dvTypeLookup = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\PropertyDataValueTypeLookup' );
+
+               $dvTypeLookup->expects( $this->any() )
+                       ->method( 'getDataValueTypeForProperty' )
+                       ->will( $this->returnValue( 'string' ) );
+
+               $storeConfig->setPropertyDataValueTypeLookup( $dvTypeLookup );
+
                $queryInterface = new MediaWikiQueryInterface(
                        $connectionProvider,
                        new ExtendedMySQLAbstraction( $connectionProvider )
                );
 
-               $instances[] = new Store( $storeConfig, $queryInterface );
+               return new Store( $storeConfig, $queryInterface );
+       }
 
-               return $instances;
+       public function testGetNameReturnType() {
+               $this->assertInternalType(
+                       'string',
+                       $this->newInstance()->getName()
+               );
+       }
+
+       public function testGetUpdaterReturnType() {
+               $this->assertInstanceOf(
+                       'Wikibase\QueryEngine\QueryStoreWriter',
+                       $this->newInstance()->getUpdater()
+               );
+       }
+
+       public function testGetQueryEngineReturnType() {
+               $this->assertInstanceOf(
+                       'Wikibase\QueryEngine\QueryEngine',
+                       $this->newInstance()->getQueryEngine()
+               );
        }
 
 }

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

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