Daniel Werner has submitted this change and it was merged. Change subject: Added SnakStore and some initial implementation ......................................................................
Added SnakStore and some initial implementation Change-Id: I9427046fe406f1ddcf8e9567ce0a11bf581e7244 --- M QueryEngine/QueryEngine.classes.php M QueryEngine/QueryEngine.mw.php A QueryEngine/QueryEngine/SQLStore/SnakStore/PropertyValueSnakStore.php A QueryEngine/QueryEngine/SQLStore/SnakStore/SnakStore.php A QueryEngine/tests/phpunit/SQLStore/SnakStore/PropertyValueSnakStoreTest.php A QueryEngine/tests/phpunit/SQLStore/SnakStore/SnakStoreTest.php 6 files changed, 237 insertions(+), 1 deletion(-) Approvals: Daniel Werner: Verified; Looks good to me, approved diff --git a/QueryEngine/QueryEngine.classes.php b/QueryEngine/QueryEngine.classes.php index b2979ce..00708b8 100644 --- a/QueryEngine/QueryEngine.classes.php +++ b/QueryEngine/QueryEngine.classes.php @@ -43,6 +43,9 @@ 'Wikibase\QueryEngine\SQLStore\DVHandler\NumberHandler', 'Wikibase\QueryEngine\SQLStore\DVHandler\StringHandler', + 'Wikibase\QueryEngine\SQLStore\SnakStore\PropertyValueSnakStore', + 'Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore', + 'Wikibase\QueryEngine\SQLStore\DataValueHandlers', 'Wikibase\QueryEngine\SQLStore\DataValueHandler', 'Wikibase\QueryEngine\SQLStore\DataValueTable', diff --git a/QueryEngine/QueryEngine.mw.php b/QueryEngine/QueryEngine.mw.php index fee8db8..8fef61a 100644 --- a/QueryEngine/QueryEngine.mw.php +++ b/QueryEngine/QueryEngine.mw.php @@ -56,7 +56,11 @@ = $dir . 'tests/phpunit/QueryStoreTest.php'; $wgAutoloadClasses['Wikibase\Test\Query\QueryStoreUpdaterTest'] - = $dir . 'tests/phpunit/QueryStoreUpdaterTest.php';} + = $dir . 'tests/phpunit/QueryStoreUpdaterTest.php'; + + $wgAutoloadClasses['Wikibase\Tests\Query\SQLStore\SnakStore\SnakStoreTest'] + = $dir . 'tests/phpunit/SQLStore/SnakStore/SnakStoreTest.php'; +} /** * Hook to add PHPUnit test cases. @@ -81,6 +85,8 @@ 'SQLStore/DVHandler/NumberHandler', 'SQLStore/DVHandler/StringHandler', + 'SQLStore/SnakStore/PropertyValueSnakStore', + 'SQLStore/DataValueHandlers', 'SQLStore/DataValueHandler', 'SQLStore/Engine', diff --git a/QueryEngine/QueryEngine/SQLStore/SnakStore/PropertyValueSnakStore.php b/QueryEngine/QueryEngine/SQLStore/SnakStore/PropertyValueSnakStore.php new file mode 100644 index 0000000..7831eba --- /dev/null +++ b/QueryEngine/QueryEngine/SQLStore/SnakStore/PropertyValueSnakStore.php @@ -0,0 +1,42 @@ +<?php + +namespace Wikibase\QueryEngine\SQLStore\SnakStore; + +use Wikibase\PropertyValueSnak; +use Wikibase\Snak; + +/** + * 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 + * + * @file + * @ingroup WikibaseSQLStore + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class PropertyValueSnakStore extends SnakStore { + + public function canStore( Snak $snak ) { + return $snak instanceof PropertyValueSnak; + } + + public function storeSnak( Snak $snak ) { + + } + +} diff --git a/QueryEngine/QueryEngine/SQLStore/SnakStore/SnakStore.php b/QueryEngine/QueryEngine/SQLStore/SnakStore/SnakStore.php new file mode 100644 index 0000000..d997a16 --- /dev/null +++ b/QueryEngine/QueryEngine/SQLStore/SnakStore/SnakStore.php @@ -0,0 +1,49 @@ +<?php + +namespace Wikibase\QueryEngine\SQLStore\SnakStore; + +use Wikibase\Snak; + +/** + * 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 + * + * @file + * @ingroup WikibaseSQLStore + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +abstract class SnakStore { + + /** + * @since 0.1 + * + * @param Snak $snak + * + * @return boolean + */ + public abstract function canStore( Snak $snak ); + + /** + * @since 0.1 + * + * @param Snak $snak + */ + public abstract function storeSnak( Snak $snak ); + +} diff --git a/QueryEngine/tests/phpunit/SQLStore/SnakStore/PropertyValueSnakStoreTest.php b/QueryEngine/tests/phpunit/SQLStore/SnakStore/PropertyValueSnakStoreTest.php new file mode 100644 index 0000000..a7eb187 --- /dev/null +++ b/QueryEngine/tests/phpunit/SQLStore/SnakStore/PropertyValueSnakStoreTest.php @@ -0,0 +1,68 @@ +<?php + +namespace Wikibase\Tests\Query\SQLStore\SnakStore; + +use DataValues\StringValue; +use Wikibase\PropertyNoValueSnak; +use Wikibase\PropertySomeValueSnak; +use Wikibase\PropertyValueSnak; +use Wikibase\QueryEngine\SQLStore\SnakStore\PropertyValueSnakStore; +use Wikibase\Snak; + +/** + * Unit tests for the Wikibase\QueryEngine\SQLStore\SnakStore\PropertyValueSnakStore class. + * + * 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 WikibaseSnakStore + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class PropertyValueSnakStoreTest extends SnakStoreTest { + + protected function getInstance() { + return new PropertyValueSnakStore(); + } + + public function canStoreProvider() { + $argLists = array(); + + $argLists[] = array( true, new PropertyValueSnak( 42, new StringValue( 'nyan' ) ) ); + $argLists[] = array( true, new PropertyValueSnak( 9001, new StringValue( 'nyan' ) ) ); + $argLists[] = array( false, new PropertyNoValueSnak( 1 ) ); + $argLists[] = array( false, new PropertyNoValueSnak( 31337 ) ); + $argLists[] = array( false, new PropertySomeValueSnak( 2 ) ); + $argLists[] = array( false, new PropertySomeValueSnak( 720101 ) ); + + return $argLists; + } + + /** + * @dataProvider canStoreProvider + */ + public function testCanStore( $canStore, Snak $snak ) { + $this->assertEquals( $canStore, $this->getInstance()->canStore( $snak ) ); + } + +} diff --git a/QueryEngine/tests/phpunit/SQLStore/SnakStore/SnakStoreTest.php b/QueryEngine/tests/phpunit/SQLStore/SnakStore/SnakStoreTest.php new file mode 100644 index 0000000..43d557b --- /dev/null +++ b/QueryEngine/tests/phpunit/SQLStore/SnakStore/SnakStoreTest.php @@ -0,0 +1,68 @@ +<?php + +namespace Wikibase\Tests\Query\SQLStore\SnakStore; + +use DataValues\StringValue; +use Wikibase\PropertyNoValueSnak; +use Wikibase\PropertySomeValueSnak; +use Wikibase\PropertyValueSnak; +use Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore; +use Wikibase\Snak; + +/** + * Unit tests for the Wikibase\QueryEngine\SQLStore\SnakStore\SnakStore 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 SnakStoreTest extends \PHPUnit_Framework_TestCase { + + /** + * @return SnakStore + */ + protected abstract function getInstance(); + + public function differentSnaksProvider() { + $argLists = array(); + + $argLists[] = array( new PropertyNoValueSnak( 42 ) ); + $argLists[] = array( new PropertySomeValueSnak( 42 ) ); + $argLists[] = array( new PropertyValueSnak( 42, new StringValue( '~=[,,_,,]:3' ) ) ); + + $argLists[] = array( new PropertyNoValueSnak( 31337 ) ); + $argLists[] = array( new PropertySomeValueSnak( 31337 ) ); + $argLists[] = array( new PropertyValueSnak( 31337, new StringValue( '~=[,,_,,]:3' ) ) ); + + return $argLists; + } + + /** + * @dataProvider differentSnaksProvider + * @param Snak $snak + */ + public function testReturnTypeOfCanUse( Snak $snak ) { + $canStore = $this->getInstance()->canStore( $snak ); + $this->assertInternalType( 'boolean', $canStore ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/58701 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9427046fe406f1ddcf8e9567ce0a11bf581e7244 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de> Gerrit-Reviewer: Henning Snater <henning.sna...@wikimedia.de> Gerrit-Reviewer: John Erling Blad <jeb...@gmail.com> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits