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

Change subject: Added QueryEnginer writing integration test
......................................................................


Added QueryEnginer writing integration test

Also wired up use case handlers in Writer facade

Change-Id: I8948c79ae1414a61f6812ca853c654804a9b64a6
---
M QueryEngine/QueryEngine.mw.php
M QueryEngine/includes/SQLStore/Factory.php
M QueryEngine/includes/SQLStore/Writer.php
A QueryEngine/tests/integration/SQLStore/WritingIntegrationTest.php
D QueryEngine/tests/phpunit/QueryStoreUpdaterTest.php
M QueryEngine/tests/phpunit/SQLStore/WriterTest.php
6 files changed, 256 insertions(+), 196 deletions(-)

Approvals:
  Henning Snater: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/QueryEngine/QueryEngine.mw.php b/QueryEngine/QueryEngine.mw.php
index 3e29f70..4596b17 100644
--- a/QueryEngine/QueryEngine.mw.php
+++ b/QueryEngine/QueryEngine.mw.php
@@ -70,12 +70,15 @@
                }
        }
 
-       $testFiles = array(
-               'SQLStore/Engine/DescriptionMatchFinderIntegrationTest',
-       );
+       $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . 
'/tests/integration/' );
 
-       foreach ( $testFiles as $file ) {
-               $files[] = __DIR__ . '/tests/integration/' . $file . '.php';
+       /**
+        * @var SplFileInfo $fileInfo
+        */
+       foreach ( new RecursiveIteratorIterator( $directoryIterator ) as 
$fileInfo ) {
+               if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
+                       $files[] = $fileInfo->getPathname();
+               }
        }
 
        return true;
diff --git a/QueryEngine/includes/SQLStore/Factory.php 
b/QueryEngine/includes/SQLStore/Factory.php
index 7999d99..b1283ef 100644
--- a/QueryEngine/includes/SQLStore/Factory.php
+++ b/QueryEngine/includes/SQLStore/Factory.php
@@ -9,6 +9,7 @@
 use Wikibase\QueryEngine\SQLStore\ClaimStore\ClaimsTable;
 use Wikibase\QueryEngine\SQLStore\Engine\DescriptionMatchFinder;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakInserter;
+use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRemover;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakRowBuilder;
 use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore;
 use Wikibase\QueryEngine\SQLStore\SnakStore\ValuelessSnakStore;
@@ -78,6 +79,25 @@
                );
        }
 
+       public function newEntityUpdater() {
+               return new EntityUpdater(
+                       $this->newEntityRemover(),
+                       $this->newEntityInserter()
+               );
+       }
+
+       public function newEntityRemover() {
+               return new EntityRemover(
+                       $this->newClaimsTable(),
+                       $this->newSnakRemover(),
+                       $this->getInternalEntityIdFinder()
+               );
+       }
+
+       public function newSnakRemover() {
+               return new SnakRemover( $this->getSnakStores() );
+       }
+
        public function newEntityTable() {
                return new EntityTable(
                        $this->queryInterface,
@@ -138,7 +158,9 @@
 
        public function newWriter() {
                return new Writer(
-                       $this->newEntityInserter()
+                       $this->newEntityInserter(),
+                       $this->newEntityUpdater(),
+                       $this->newEntityRemover()
                );
        }
 
diff --git a/QueryEngine/includes/SQLStore/Writer.php 
b/QueryEngine/includes/SQLStore/Writer.php
index aad1e3b..af10b2d 100644
--- a/QueryEngine/includes/SQLStore/Writer.php
+++ b/QueryEngine/includes/SQLStore/Writer.php
@@ -47,14 +47,13 @@
 class Writer implements QueryStoreWriter {
 
        private $entityInserter;
+       private $entityUpdater;
+       private $entityRemover;
 
-       /**
-        * @since 0.1
-        *
-        * @param EntityInserter $entityInserter
-        */
-       public function __construct( EntityInserter $entityInserter ) {
-               $this->entityInserter = $entityInserter;
+       public function __construct( EntityInserter $inserter, EntityUpdater 
$updater, EntityRemover $remover ) {
+               $this->entityInserter = $inserter;
+               $this->entityUpdater = $updater;
+               $this->entityRemover = $remover;
        }
 
        /**
@@ -76,7 +75,7 @@
         * @param Entity $entity
         */
        public function updateEntity( Entity $entity ) {
-               // TODO
+               $this->entityUpdater->updateEntity( $entity );
        }
 
        /**
@@ -87,7 +86,7 @@
         * @param Entity $entity
         */
        public function deleteEntity( Entity $entity ) {
-               // TODO
+               $this->entityRemover->removeEntity( $entity );
        }
 
 }
diff --git a/QueryEngine/tests/integration/SQLStore/WritingIntegrationTest.php 
b/QueryEngine/tests/integration/SQLStore/WritingIntegrationTest.php
new file mode 100644
index 0000000..b88a06a
--- /dev/null
+++ b/QueryEngine/tests/integration/SQLStore/WritingIntegrationTest.php
@@ -0,0 +1,199 @@
+<?php
+
+namespace Wikibase\QueryEngine\Integration\SQLStore;
+
+use Ask\Language\Description\Description;
+use Ask\Language\Description\SomeProperty;
+use Ask\Language\Description\ValueDescription;
+use Ask\Language\Option\QueryOptions;
+use DataValues\NumberValue;
+use DataValues\StringValue;
+use NullMessageReporter;
+use Wikibase\Claims;
+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\DVHandler\StringHandler;
+use Wikibase\QueryEngine\SQLStore\Store;
+use Wikibase\QueryEngine\SQLStore\StoreConfig;
+use Wikibase\Test\ClaimListAccessTest;
+
+/**
+ * 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
+ *
+ * @ingroup WikibaseQueryEngineTest
+ *
+ * @group Wikibase
+ * @group WikibaseQueryEngine
+ * @group WikibaseQueryEngineIntegration
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+class WritingIntegrationTest 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();
+       }
+
+       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(
+                               'string' => new StringHandler( new 
DataValueTable(
+                                       new TableDefinition(
+                                               'string',
+                                               array(
+                                                       new FieldDefinition( 
'value', FieldDefinition::TYPE_TEXT, false ),
+                                               )
+                                       ),
+                                       'value',
+                                       'value',
+                                       'value'
+                               ) )
+                       )
+               );
+
+               $propertyDvTypeLookup = $this->getMock( 
'Wikibase\QueryEngine\SQLStore\PropertyDataValueTypeLookup' );
+
+               $propertyDvTypeLookup->expects( $this->any() )
+                       ->method( 'getDataValueTypeForProperty' )
+                       ->will( $this->returnValue( 'string' ) );
+
+               $config->setPropertyDataValueTypeLookup( $propertyDvTypeLookup 
);
+
+               return new Store( $config, $queryInterface );
+       }
+
+       public function testInsertAndRemoveItem() {
+               $item = Item::newEmpty();
+               $item->setId( 8888 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 42, new 
StringValue( 'Awesome' ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+
+               $propertyDescription = new SomeProperty(
+                       new EntityId( 'property', 42 ),
+                       new ValueDescription( new StringValue( 'Awesome' ) )
+               );
+
+               $this->assertEquals(
+                       array( 88880 ),
+                       $this->findMatchingEntities( $propertyDescription )
+               );
+
+               $this->store->getUpdater()->deleteEntity( $item );
+
+               $this->assertEquals(
+                       array(),
+                       $this->findMatchingEntities( $propertyDescription )
+               );
+       }
+
+       /**
+        * @param Description $description
+        * @return int[]
+        */
+       protected function findMatchingEntities( Description $description ) {
+               $matchFinder = $this->store->getDescriptionMatchFinder();
+
+               $queryOptions = new QueryOptions(
+                       100,
+                       0
+               );
+
+               return $matchFinder->findMatchingEntities( $description, 
$queryOptions );
+       }
+
+       public function testUpdateItem() {
+               $item = Item::newEmpty();
+               $item->setId( 4444 );
+
+               $claim = $item->newClaim( new PropertyValueSnak( 42, new 
StringValue( 'Awesome' ) ) );
+               $item->addClaim( $claim );
+
+               $this->store->getUpdater()->insertEntity( $item );
+
+               $item->setClaims( new Claims( array(
+                       $item->newClaim( new PropertyValueSnak( 42, new 
StringValue( 'Foo' ) ) )
+               ) ) );
+
+               $this->store->getUpdater()->updateEntity( $item );
+
+               $propertyDescription = new SomeProperty(
+                       new EntityId( 'property', 42 ),
+                       new ValueDescription( new StringValue( 'Foo' ) )
+               );
+
+               $this->assertEquals(
+                       array( 44440 ),
+                       $this->findMatchingEntities( $propertyDescription )
+               );
+
+               $propertyDescription = new SomeProperty(
+                       new EntityId( 'property', 42 ),
+                       new ValueDescription( new StringValue( 'Awesome' ) )
+               );
+
+               $this->assertEquals(
+                       array(),
+                       $this->findMatchingEntities( $propertyDescription )
+               );
+       }
+
+}
diff --git a/QueryEngine/tests/phpunit/QueryStoreUpdaterTest.php 
b/QueryEngine/tests/phpunit/QueryStoreUpdaterTest.php
deleted file mode 100644
index a2f7766..0000000
--- a/QueryEngine/tests/phpunit/QueryStoreUpdaterTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-namespace Wikibase\QueryEngine\Tests;
-
-use Wikibase\Item;
-use Wikibase\QueryEngine\QueryStoreWriter;
-
-/**
- * Base test class for Wikibase\QueryEngine\QueryStoreUpdater 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 < jeroended...@gmail.com >
- */
-abstract class QueryStoreUpdaterTest extends \PHPUnit_Framework_TestCase {
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryStoreWriter[]
-        */
-       protected abstract function getInstances();
-
-       /**
-        * @since 0.1
-        *
-        * @return QueryStoreWriter[][]
-        */
-       public function instanceProvider() {
-               $argLists = array();
-
-               foreach ( $this->getInstances() as $instance ) {
-                       $argLists[] = array( $instance );
-               }
-
-               return $argLists;
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryStoreWriter $updater
-        */
-       public function testInsertEntityDoesNotFatal( QueryStoreWriter $updater 
) {
-               $item = Item::newEmpty();
-               $item->setId( 42 );
-
-               $updater->insertEntity( $item );
-
-               $this->assertTrue( true );
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryStoreWriter $updater
-        */
-       public function testUpdateEntityDoesNotFatal( QueryStoreWriter $updater 
) {
-               $item = Item::newEmpty();
-               $item->setId( 42 );
-
-               $updater->updateEntity( $item );
-
-               $this->assertTrue( true );
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        *
-        * @param QueryStoreWriter $updater
-        */
-       public function testDeleteEntityDoesNotFatal( QueryStoreWriter $updater 
) {
-               $item = Item::newEmpty();
-               $item->setId( 42 );
-
-               $updater->deleteEntity( $item );
-
-               $this->assertTrue( true );
-       }
-
-}
diff --git a/QueryEngine/tests/phpunit/SQLStore/WriterTest.php 
b/QueryEngine/tests/phpunit/SQLStore/WriterTest.php
index f93cf34..e3cd047 100644
--- a/QueryEngine/tests/phpunit/SQLStore/WriterTest.php
+++ b/QueryEngine/tests/phpunit/SQLStore/WriterTest.php
@@ -44,95 +44,32 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
-class WriterTest extends QueryStoreUpdaterTest {
+class WriterTest extends \PHPUnit_Framework_TestCase {
 
-       /**
-        * @see QueryStoreUpdaterTest::getInstances
-        *
-        * @since 0.1
-        *
-        * @return Writer[]
-        */
-       protected function getInstances() {
-               $instances = array();
-
+       public function testFacadeForwardsCalls() {
                $entityInserter = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityInserter' )
                        ->disableOriginalConstructor()->getMock();
 
-               $instances[] = new Writer( $entityInserter );
-
-               return $instances;
-       }
-
-       protected function newStoreSchema() {
-               $dataValueHandlers = array();
-
-               $dataValueHandlers['boolean'] = new BooleanHandler( new 
DataValueTable(
-                       new TableDefinition(
-                               'boolean',
-                               array(
-                                       new FieldDefinition( 'value', 
FieldDefinition::TYPE_BOOLEAN, false ),
-                               )
-                       ),
-                       'value',
-                       'value'
-               ) );
-
-               $dataValueHandlers['monolingualtext'] = new 
MonolingualTextHandler( new DataValueTable(
-                       new TableDefinition(
-                               'mono_text',
-                               array(
-                                       new FieldDefinition( 'text', 
FieldDefinition::TYPE_TEXT, false ),
-                                       new FieldDefinition( 'language', 
FieldDefinition::TYPE_TEXT, false ),
-                                       new FieldDefinition( 'json', 
FieldDefinition::TYPE_TEXT, false ),
-                               )
-                       ),
-                       'json',
-                       'text',
-                       'text'
-               ) );
-
-               return new Schema( new StoreConfig( 'foobar', 'nyan_', 
$dataValueHandlers ) );
-       }
-
-       public function entityWithoutClaimsProvider() {
-               $argLists = array();
-
-               $item = Item::newEmpty();
-               $item->setId( 42 );
-
-               $argLists[] = array( $item );
-
-
-               $item = Item::newEmpty();
-               $item->setId( 31337 );
-
-               $argLists[] = array( $item );
-
-
-               $property = Property::newEmpty();
-               $property->setDataTypeId( 'string' );
-               $property->setId( 9001 );
-
-               $argLists[] = array( $property );
-
-               return $argLists;
-       }
-
-       /**
-        * @dataProvider entityWithoutClaimsProvider
-        */
-       public function testInsertEntityWithoutClaims( Entity $entity ) {
-               $entityInserter = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityInserter' )
+               $entityUpdater = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityUpdater' )
                        ->disableOriginalConstructor()->getMock();
 
-               $entityInserter->expects( $this->once() )
-                       ->method( 'insertEntity' )
-                       ->with( $this->equalTo( $entity ) );
+               $entityRemover = $this->getMockBuilder( 
'Wikibase\QueryEngine\SQLStore\EntityRemover' )
+                       ->disableOriginalConstructor()->getMock();
 
-               $updater = new Writer( $entityInserter );
+               $writer = new Writer( $entityInserter, $entityUpdater, 
$entityRemover );
 
-               $updater->insertEntity( $entity );
+               $entityRemover->expects( $this->exactly( 1 ) )->method( 
'removeEntity' );
+               $entityUpdater->expects( $this->exactly( 2 ) )->method( 
'updateEntity' );
+               $entityInserter->expects( $this->exactly( 3 ) )->method( 
'insertEntity' );
+
+               $writer->deleteEntity( Item::newEmpty() );
+
+               $writer->updateEntity( Item::newEmpty() );
+               $writer->updateEntity( Item::newEmpty() );
+
+               $writer->insertEntity( Item::newEmpty() );
+               $writer->insertEntity( Item::newEmpty() );
+               $writer->insertEntity( Item::newEmpty() );
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8948c79ae1414a61f6812ca853c654804a9b64a6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Henning Snater <henning.sna...@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