jenkins-bot has submitted this change and it was merged.

Change subject: Work on DescriptionMatchFinderIntegrationTest
......................................................................


Work on DescriptionMatchFinderIntegrationTest

Change-Id: Ic9290446863e10e88b5b9a12be8ce9a0dd601721
---
M QueryEngine/QueryEngine.mw.php
M QueryEngine/includes/SQLStore/Factory.php
M QueryEngine/includes/SQLStore/Store.php
M QueryEngine/includes/SQLStore/StoreConfig.php
M QueryEngine/phpunit.xml.dist
A 
QueryEngine/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
M QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
7 files changed, 255 insertions(+), 3 deletions(-)

Approvals:
  Denny Vrandecic: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/QueryEngine/QueryEngine.mw.php b/QueryEngine/QueryEngine.mw.php
index e83fdb7..456ea2b 100644
--- a/QueryEngine/QueryEngine.mw.php
+++ b/QueryEngine/QueryEngine.mw.php
@@ -91,6 +91,14 @@
                $files[] = __DIR__ . '/tests/phpunit/' . $file . 'Test.php';
        }
 
+       $testFiles = array(
+               'SQLStore/Engine/DescriptionMatchFinderIntegrationTest',
+       );
+
+       foreach ( $testFiles as $file ) {
+               $files[] = __DIR__ . '/tests/integration/' . $file . '.php';
+       }
+
        return true;
        // @codeCoverageIgnoreEnd
 };
diff --git a/QueryEngine/includes/SQLStore/Factory.php 
b/QueryEngine/includes/SQLStore/Factory.php
index 6fc246a..c00562c 100644
--- a/QueryEngine/includes/SQLStore/Factory.php
+++ b/QueryEngine/includes/SQLStore/Factory.php
@@ -6,6 +6,7 @@
 use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimInserter;
 use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimRowBuilder;
 use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimsTable;
+use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRowBuilder;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore;
@@ -141,4 +142,16 @@
                );
        }
 
+       /**
+        * @return DescriptionMatchFinder
+        */
+       public function newDescriptionMatchFinder() {
+               return new DescriptionMatchFinder(
+                       $this->queryInterface,
+                       $this->schema,
+                       $this->config->getPropertyDataValueTypeLookup(),
+                       $this->getInternalEntityIdFinder()
+               );
+       }
+
 }
diff --git a/QueryEngine/includes/SQLStore/Store.php 
b/QueryEngine/includes/SQLStore/Store.php
index c5773e5..ac14857 100644
--- a/QueryEngine/includes/SQLStore/Store.php
+++ b/QueryEngine/includes/SQLStore/Store.php
@@ -6,6 +6,7 @@
 use Wikibase\Database\QueryInterface;
 use Wikibase\Database\TableBuilder;
 use Wikibase\QueryEngine\QueryStore;
+use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder;
 use Wikibase\QueryEngine\SQLStore\Engine\Engine;
 
 /**
@@ -74,10 +75,14 @@
                $this->config = $config;
                $this->queryInterface = $queryInterface;
                $this->factory = new Factory( $config, $queryInterface );
+
+               $this->tableBuilder = new TableBuilder( $this->queryInterface );
        }
 
        /**
         * Sets the table builder to use for creating tables.
+        *
+        * @deprecated TODO: move to config
         *
         * @since 0.1
         *
@@ -142,4 +147,13 @@
                );
        }
 
+       /**
+        * TODO: figure out how to merge this into the QueryEngine interface
+        *
+        * @return DescriptionMatchFinder
+        */
+       public function getDescriptionMatchFinder() {
+               return $this->factory->newDescriptionMatchFinder();
+       }
+
 }
diff --git a/QueryEngine/includes/SQLStore/StoreConfig.php 
b/QueryEngine/includes/SQLStore/StoreConfig.php
index 0ddbd12..e5ad466 100644
--- a/QueryEngine/includes/SQLStore/StoreConfig.php
+++ b/QueryEngine/includes/SQLStore/StoreConfig.php
@@ -131,6 +131,7 @@
        public function getEntityTypeMap() {
                return array(
                        'item' => 0,
+                       'property' => 1,
                );
        }
 
diff --git a/QueryEngine/phpunit.xml.dist b/QueryEngine/phpunit.xml.dist
index 916c615..38769f8 100644
--- a/QueryEngine/phpunit.xml.dist
+++ b/QueryEngine/phpunit.xml.dist
@@ -14,7 +14,8 @@
          verbose="true">
     <testsuites>
         <testsuite name="QueryEngine">
-            <directory>tests</directory>
+            <directory>tests/phpunit</directory>
+            <exclude>tests/integration</exclude>
         </testsuite>
     </testsuites>
 </phpunit>
diff --git 
a/QueryEngine/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
 
b/QueryEngine/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
new file mode 100644
index 0000000..c531182
--- /dev/null
+++ 
b/QueryEngine/tests/integration/SQLStore/Engine/DescriptionMatchFinderIntegrationTest.php
@@ -0,0 +1,215 @@
+<?php
+
+namespace Wikibase\QueryEngine\Integration\SQLStore\Engine;
+
+use Ask\Language\Description\SomeProperty;
+use Ask\Language\Description\ValueDescription;
+use Ask\Language\Option\QueryOptions;
+use DataValues\NumberValue;
+use NullMessageReporter;
+use Wikibase\Claim;
+use Wikibase\Database\FieldDefinition;
+use Wikibase\Database\LazyDBConnectionProvider;
+use Wikibase\Database\MediaWikiQueryInterface;
+use Wikibase\Database\MWDB\ExtendedMySQLAbstraction;
+use Wikibase\Database\TableDefinition;
+use Wikibase\EntityId;
+use Wikibase\Item;
+use Wikibase\PropertyValueSnak;
+use Wikibase\QueryEngine\SQLStore\DataValueTable;
+use Wikibase\QueryEngine\SQLStore\DVHandler\NumberHandler;
+use Wikibase\QueryEngine\SQLStore\Store;
+use Wikibase\QueryEngine\SQLStore\StoreConfig;
+
+/**
+ * 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
+ * @group WikibaseQueryEngineIntegration
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+class DescriptionMatchFinderIntegrationTest extends 
\PHPUnit_Framework_TestCase {
+
+       /**
+        * @var Store
+        */
+       protected $store;
+
+       public function setUp() {
+               if ( !defined( 'MEDIAWIKI' ) || wfGetDB( DB_MASTER )->getType() 
!== 'mysql' ) {
+                       $this->markTestSkipped( 'Can only run 
DescriptionMatchFinderIntegrationTest on MySQL' );
+               }
+
+               parent::setUp();
+
+               $this->store = $this->newStore();
+
+               $this->store->getSetup( new NullMessageReporter() )->install();
+
+               $this->insertEntities();
+       }
+
+       public function tearDown() {
+               if ( isset( $this->store ) ) {
+                       $this->store->getSetup( new NullMessageReporter() 
)->uninstall();
+               }
+       }
+
+       protected function newStore() {
+               $dbConnectionProvider = new LazyDBConnectionProvider( DB_MASTER 
);
+
+               $queryInterface = new MediaWikiQueryInterface(
+                       $dbConnectionProvider,
+                       new ExtendedMySQLAbstraction( $dbConnectionProvider )
+               );
+
+               $config = new StoreConfig(
+                       'test_store',
+                       'integrationtest_',
+                       array(
+                               'number' => new NumberHandler( new 
DataValueTable(
+                                       new TableDefinition(
+                                               'number_table',
+                                               array(
+                                                       new FieldDefinition( 
'value', FieldDefinition::TYPE_FLOAT, false ),
+                                                       new FieldDefinition( 
'json', FieldDefinition::TYPE_TEXT, false ),
+                                               )
+                                       ),
+                                       'json',
+                                       'value',
+                                       'value'
+                               ) )
+                       )
+               );
+
+               $propertyDvTypeLookup = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\PropertyDataValueTypeLookup' );
+
+               $propertyDvTypeLookup->expects( $this->any() )
+                       ->method( 'getDataValueTypeForProperty' )
+                       ->will( $this->returnValue( 'number' ) );
+
+               $config->setPropertyDataValueTypeLookup( $propertyDvTypeLookup 
);
+
+               return new Store( $config, $queryInterface );
+       }
+
+       protected function insertEntities() {
+               $item = Item::newEmpty();
+               $item->setId( 1112 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 42, new 
NumberValue( 1337 ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+
+
+               $item = Item::newEmpty();
+               $item->setId( 1113 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 43, new 
NumberValue( 1337 ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+
+
+               $item = Item::newEmpty();
+               $item->setId( 1114 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 42, new 
NumberValue( 72010 ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+
+
+               $item = Item::newEmpty();
+               $item->setId( 1115 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 42, new 
NumberValue( 1337 ) ) );
+               $item->addClaim( $claim );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 43, new 
NumberValue( 1 ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+       }
+
+       /**
+        * @dataProvider somePropertyProvider
+        */
+       public function testFindMatchingEntitiesWithSomeProperty( SomeProperty 
$description, array $expectedIds ) {
+               $matchFinder = $this->store->getDescriptionMatchFinder();
+
+               $queryOptions = new QueryOptions(
+                       100,
+                       0
+               );
+
+               $matchingEntityIds = $matchFinder->findMatchingEntities( 
$description, $queryOptions );
+
+               $this->assertInternalType( 'array', $matchingEntityIds );
+               $this->assertContainsOnly( 'int', $matchingEntityIds );
+
+               $this->assertEquals( $expectedIds, $matchingEntityIds );
+       }
+
+       public function somePropertyProvider() {
+               $argLists = array();
+
+               $argLists[] = array(
+                       new SomeProperty(
+                               new EntityId( 'property', 42 ),
+                               new ValueDescription( new NumberValue( 1337 ) )
+                       ),
+                       array( 11120, 11150 )
+               );
+
+               $argLists[] = array(
+                       new SomeProperty(
+                               new EntityId( 'property', 1 ),
+                               new ValueDescription( new NumberValue( 1337 ) )
+                       ),
+                       array()
+               );
+
+               $argLists[] = array(
+                       new SomeProperty(
+                               new EntityId( 'property', 43 ),
+                               new ValueDescription( new NumberValue( 1337 ) )
+                       ),
+                       array( 11130 )
+               );
+
+               $argLists[] = array(
+                       new SomeProperty(
+                               new EntityId( 'property', 42 ),
+                               new ValueDescription( new NumberValue( 72010 ) )
+                       ),
+                       array( 11140 )
+               );
+
+               return $argLists;
+       }
+
+
+}
diff --git 
a/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php 
b/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
index a91fb7b..77518d1 100644
--- a/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
+++ b/QueryEngine/tests/phpunit/SQLStore/Engine/DescriptionMatchFinderTest.php
@@ -69,10 +69,10 @@
                        ->method( 'select' )
                        ->with(
                                $this->equalTo( 'tablename' ),
-                               $this->equalTo( array( 'entity_id' ) )
+                               $this->equalTo( array( 'subject_id' ) )
                        )
                        ->will( $this->returnValue( array(
-                               (object)array( 'entity_id' => 10 )
+                               (object)array( 'subject_id' => 10 )
                        ) ) );
 
                $schema = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\Schema' )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic9290446863e10e88b5b9a12be8ce9a0dd601721
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to