Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Registered Wikibase\Repo\Database classes and added test for 
FieldDefinition
......................................................................

Registered Wikibase\Repo\Database classes and added test for FieldDefinition

Change-Id: I97f40f5b51f6a39e9deaa286b5fdcd4f9b7498a6
---
M repo/Wikibase.hooks.php
M repo/config/Wikibase.experimental.php
M repo/includes/Database/FieldDefinition.php
M repo/includes/Query/SQLStore/Setup.php
A repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
5 files changed, 133 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/28/50628/1

diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index c1c7b88..002f238 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -185,6 +185,8 @@
                        'content/PropertyContent',
                        'content/PropertyHandler',
 
+                       'Database/FieldDefinition',
+
                        'specials/SpecialCreateItem',
                        'specials/SpecialItemDisambiguation',
                        'specials/SpecialItemByTitle',
diff --git a/repo/config/Wikibase.experimental.php 
b/repo/config/Wikibase.experimental.php
index e2c7650..57d6fb5 100644
--- a/repo/config/Wikibase.experimental.php
+++ b/repo/config/Wikibase.experimental.php
@@ -46,6 +46,18 @@
 $wgAutoloadClasses['Wikibase\QueryHandler']                    = $dir . 
'includes/content/QueryHandler.php';
 
 
+
+foreach ( array(
+                         'Wikibase\Repo\Database\FieldDefinition',
+                         'Wikibase\Repo\Database\MediaWikiQueryInterface',
+                         'Wikibase\Repo\Database\QueryInterface',
+                         'Wikibase\Repo\Database\TableBuilder',
+                         'Wikibase\Repo\Database\TableDefinition',
+                 ) as $class ) {
+
+       $wgAutoloadClasses[$class] = $dir . 'includes' . str_replace( '\\', 
'/', substr( $class, 13 ) ) . '.php';
+}
+
 if ( !class_exists( 'MessageReporter' ) ) {
        $wgAutoloadClasses['MessageReporter'] = $dir . 
'includes/MessageReporter.php';
        $wgAutoloadClasses['ObservableMessageReporter'] = $dir . 
'includes/MessageReporter.php';
diff --git a/repo/includes/Database/FieldDefinition.php 
b/repo/includes/Database/FieldDefinition.php
index 9672d3d..01f3024 100644
--- a/repo/includes/Database/FieldDefinition.php
+++ b/repo/includes/Database/FieldDefinition.php
@@ -70,7 +70,7 @@
        /**
         * @since 0.4
         *
-        * @var string
+        * @var string|null
         */
        private $index;
 
@@ -96,7 +96,7 @@
         * @param mixed $default
         * @param string|null $attributes
         * @param boolean $null
-        * @param string $index
+        * @param string|null $index
         * @param boolean $autoIncrement
         *
         * @throws InvalidArgumentException
@@ -114,7 +114,7 @@
                        throw new InvalidArgumentException( 'The $null 
parameter needs to be a boolean' );
                }
 
-               if ( !is_string( $autoIncrement ) ) {
+               if ( !is_null( $index ) && !is_string( $index ) ) {
                        throw new InvalidArgumentException( 'The $index 
parameter needs to be a string' );
                }
 
diff --git a/repo/includes/Query/SQLStore/Setup.php 
b/repo/includes/Query/SQLStore/Setup.php
index 174595e..489026c 100644
--- a/repo/includes/Query/SQLStore/Setup.php
+++ b/repo/includes/Query/SQLStore/Setup.php
@@ -29,6 +29,7 @@
         *
         * @param Store $sqlStore
         * @param TableBuilder $tableBuilder
+        * @param MessageReporter|null $messageReporter
         */
        public function __construct( Store $sqlStore, TableBuilder 
$tableBuilder, MessageReporter $messageReporter = null ) {
                $this->store = $sqlStore;
diff --git a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php 
b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
new file mode 100644
index 0000000..29943f8
--- /dev/null
+++ b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Wikibase\Repo\Test\Database;
+
+use Wikibase\Repo\Database\FieldDefinition;
+
+/**
+ * Unit test Wikibase\Repo\Database\FieldDefinitionTest 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.4
+ *
+ * @ingroup WikibaseRepoTest
+ *
+ * @group Wikibase
+ * @group WikibaseRepo
+ * @group WikibaseDatabase
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+class FieldDefinitionTest extends \MediaWikiTestCase {
+
+       public function instanceProvider() {
+               $instances = array();
+
+               $instances[] = new FieldDefinition(
+                       'names',
+                       FieldDefinition::TYPE_TEXT
+               );
+
+               $instances[] = new FieldDefinition(
+                       'numbers',
+                       FieldDefinition::TYPE_FLOAT
+               );
+
+               $instances[] = new FieldDefinition(
+                       'stuffs',
+                       FieldDefinition::TYPE_INTEGER,
+                       42,
+                       FieldDefinition::ATTRIB_UNSIGNED,
+                       false
+               );
+
+               $instances[] = new FieldDefinition(
+                       'stuffs',
+                       FieldDefinition::TYPE_INTEGER,
+                       null,
+                       null,
+                       true
+               );
+
+               $instances[] = new FieldDefinition(
+                       'stuffs',
+                       FieldDefinition::TYPE_INTEGER,
+                       null,
+                       null,
+                       true,
+                       null,
+                       true
+               );
+
+               return $this->arrayWrap( $instances );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @param FieldDefinition $field
+        */
+       public function testReturnValueOfGetName( FieldDefinition $field ) {
+               $this->assertInternalType( 'string', $field->getName() );
+
+               $newField = new FieldDefinition( $field->getName(), 
$field->getType() );
+
+               $this->assertEquals(
+                       $field->getName(),
+                       $newField->getName(),
+                       'The FieldDefinition name is set and obtained correctly'
+               );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @param FieldDefinition $field
+        */
+       public function testReturnValueOfGetType( FieldDefinition $field ) {
+               $this->assertInternalType( 'string', $field->getType() );
+
+               $newField = new FieldDefinition( $field->getName(), 
$field->getType() );
+
+               $this->assertEquals(
+                       $field->getType(),
+                       $newField->getType(),
+                       'The FieldDefinition type is set and obtained correctly'
+               );
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97f40f5b51f6a39e9deaa286b5fdcd4f9b7498a6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

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

Reply via email to