Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Added to SetupTest and moved mock service object implementions 
to non-test code
......................................................................

Added to SetupTest and moved mock service object implementions to non-test code

Change-Id: I88a96b633aa29d0b7e4d6fe5fa2ecd472fad28a6
---
M repo/config/Wikibase.experimental.php
A repo/includes/Database/ObservableQueryInterface.php
M repo/includes/MessageReporter.php
M repo/tests/phpunit/includes/Database/TableBuilderTest.php
M repo/tests/phpunit/includes/Query/SQLStore/SetupTest.php
5 files changed, 147 insertions(+), 54 deletions(-)


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

diff --git a/repo/config/Wikibase.experimental.php 
b/repo/config/Wikibase.experimental.php
index 406379c..e98f64c 100644
--- a/repo/config/Wikibase.experimental.php
+++ b/repo/config/Wikibase.experimental.php
@@ -49,6 +49,7 @@
 $classes = array(
        'Wikibase\Repo\Database\FieldDefinition',
        'Wikibase\Repo\Database\MediaWikiQueryInterface',
+       'Wikibase\Repo\Database\ObservableQueryInterface',
        'Wikibase\Repo\Database\QueryInterface',
        'Wikibase\Repo\Database\TableBuilder',
        'Wikibase\Repo\Database\TableDefinition',
@@ -74,6 +75,7 @@
 if ( !class_exists( 'MessageReporter' ) ) {
        $wgAutoloadClasses['MessageReporter'] = $dir . 
'includes/MessageReporter.php';
        $wgAutoloadClasses['ObservableMessageReporter'] = $dir . 
'includes/MessageReporter.php';
+       $wgAutoloadClasses['NullMessageReporter'] = $dir . 
'includes/MessageReporter.php';
 }
 
 if ( defined( 'MW_PHPUNIT_TEST' ) ) {
diff --git a/repo/includes/Database/ObservableQueryInterface.php 
b/repo/includes/Database/ObservableQueryInterface.php
new file mode 100644
index 0000000..c4b9b56
--- /dev/null
+++ b/repo/includes/Database/ObservableQueryInterface.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Wikibase\Repo\Database;
+
+use Wikibase\Repo\Database\QueryInterface;
+
+/**
+ * Mock implementation of the QueryInterface interface that allows
+ * tests to assert that certain methods where called.
+ *
+ * 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 wd.db
+ *
+ * @file
+ * @ingroup WikibaseRepo
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ObservableQueryInterface implements QueryInterface {
+
+       /**
+        * @var callable[]
+        */
+       private $callbacks = array();
+
+       /**
+        * @param string $method
+        * @param callable $callback
+        */
+       public function registerCallback( $method, $callback ) {
+               $this->callbacks[$method] = $callback;
+       }
+
+       private function runCallbacks( $method, $args ) {
+               if ( array_key_exists( $method, $this->callbacks ) ) {
+                       call_user_func_array( $this->callbacks[$method], $args 
);
+               }
+       }
+
+       /**
+        * @see QueryInterface::tableExists
+        *
+        * @param string $tableName
+        *
+        * @return boolean
+        */
+       public function tableExists( $tableName ) {
+               $this->runCallbacks( __FUNCTION__, func_get_args() );
+       }
+
+}
diff --git a/repo/includes/MessageReporter.php 
b/repo/includes/MessageReporter.php
index fd13294..7d69eeb 100644
--- a/repo/includes/MessageReporter.php
+++ b/repo/includes/MessageReporter.php
@@ -123,3 +123,43 @@
        }
 
 }
+
+/**
+ * Mock implementation of the MessageReporter interface that
+ * does nothing with messages it receives.
+ *
+ * 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 1.21
+ * @file
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class NullMessageReporter implements MessageReporter {
+
+       /**
+        * @see MessageReporter::reportMessage
+        *
+        * @since 1.21
+        *
+        * @param string $message
+        */
+       public function reportMessage( $message ) {
+               // no-op
+       }
+
+}
diff --git a/repo/tests/phpunit/includes/Database/TableBuilderTest.php 
b/repo/tests/phpunit/includes/Database/TableBuilderTest.php
index 5fa496c..1f8dfde 100644
--- a/repo/tests/phpunit/includes/Database/TableBuilderTest.php
+++ b/repo/tests/phpunit/includes/Database/TableBuilderTest.php
@@ -5,6 +5,8 @@
 use Wikibase\Repo\Database\TableBuilder;
 use Wikibase\Repo\Database\FieldDefinition;
 use Wikibase\Repo\Database\TableDefinition;
+use Wikibase\Repo\Database\ObservableQueryInterface;
+use NullMessageReporter;
 
 /**
  * Unit tests for the Wikibase\Repo\Database\TableBuilder class.
@@ -81,56 +83,3 @@
        }
 
 }
-
-use Wikibase\Repo\Database\QueryInterface;
-
-class ObservableQueryInterface implements QueryInterface {
-
-       /**
-        * @var callable[]
-        */
-       private $callbacks = array();
-
-       /**
-        * @param string $method
-        * @param callable $callback
-        */
-       public function registerCallback( $method, $callback ) {
-               $this->callbacks[$method] = $callback;
-       }
-
-       private function runCallbacks( $method, $args ) {
-               if ( array_key_exists( $method, $this->callbacks ) ) {
-                       call_user_func_array( $this->callbacks[$method], $args 
);
-               }
-       }
-
-       /**
-        * @see QueryInterface::tableExists
-        *
-        * @param string $tableName
-        *
-        * @return boolean
-        */
-       public function tableExists( $tableName ) {
-               $this->runCallbacks( __FUNCTION__, func_get_args() );
-       }
-
-}
-
-use MessageReporter;
-
-class NullMessageReporter implements MessageReporter {
-
-       /**
-        * @see MessageReporter::reportMessage
-        *
-        * @since wd.db
-        *
-        * @param string $message
-        */
-       public function reportMessage( $message ) {
-               // no-op
-       }
-
-}
\ No newline at end of file
diff --git a/repo/tests/phpunit/includes/Query/SQLStore/SetupTest.php 
b/repo/tests/phpunit/includes/Query/SQLStore/SetupTest.php
index 825c593..cbac7ec 100644
--- a/repo/tests/phpunit/includes/Query/SQLStore/SetupTest.php
+++ b/repo/tests/phpunit/includes/Query/SQLStore/SetupTest.php
@@ -36,6 +36,42 @@
  */
 class SetupTest extends \MediaWikiTestCase {
 
-       // TODO
+       /**
+        * @since wd.qe
+        *
+        * @return Setup[]
+        */
+       protected function getInstances() {
+               $instances = array();
+
+               $instances[] = new Setup(
+                       new \Wikibase\Repo\Query\SQLStore\Store( 'foo', array() 
),
+                       new \Wikibase\Repo\Database\TableBuilder( new 
\Wikibase\Repo\Database\ObservableQueryInterface() )
+               );
+
+               return $instances;
+       }
+
+       /**
+        * @since wd.qe
+        *
+        * @return Setup[][]
+        */
+       public function instanceProvider() {
+               return $this->arrayWrap( $this->getInstances() );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @param Setup $storeSetup
+        */
+       public function testExecutionOfRun( Setup $storeSetup ) {
+               $storeSetup->run();
+
+               $this->assertTrue( true );
+       }
+
+       // TODO: add more detailed tests
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88a96b633aa29d0b7e4d6fe5fa2ecd472fad28a6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
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