Tobias Gritschacher has submitted this change and it was merged.
Change subject: Add test runner for WikibaseDatabase component and got rid of
bad dependencies so tests can be run on their own
......................................................................
Add test runner for WikibaseDatabase component and got rid of bad dependencies
so tests can be run on their own
Change-Id: Ice733240915539418c272385293ac59929a74361
---
M Database/Database.classes.php
M Database/Database/FieldDefinition.php
A Database/Database/MessageReporter.php
M Database/Database/TableBuilder.php
M Database/Database/TableDefinition.php
M Database/dependencies.txt
A Database/phpunit.xml.dist
A Database/tests/bootstrap.php
M Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
M Database/tests/phpunit/TableBuilderTest.php
A Database/tests/testLoader.php
11 files changed, 131 insertions(+), 11 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Database/Database.classes.php b/Database/Database.classes.php
index 376c726..74359d1 100644
--- a/Database/Database.classes.php
+++ b/Database/Database.classes.php
@@ -34,6 +34,7 @@
'Wikibase\Database\FieldDefinition',
'Wikibase\Database\MediaWikiQueryInterface',
+ 'Wikibase\Database\MessageReporter',
'Wikibase\Database\QueryInterface',
'Wikibase\Database\TableBuilder',
'Wikibase\Database\TableDefinition',
diff --git a/Database/Database/FieldDefinition.php
b/Database/Database/FieldDefinition.php
index 1d786e5..1797c4b 100644
--- a/Database/Database/FieldDefinition.php
+++ b/Database/Database/FieldDefinition.php
@@ -5,7 +5,7 @@
use InvalidArgumentException;
/**
- * Definition of a database table field.
+ * Definition of a database table field. Immutable.
*
* 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
@@ -30,7 +30,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class FieldDefinition implements \Immutable {
+class FieldDefinition {
/**
* @since 0.1
diff --git a/Database/Database/MessageReporter.php
b/Database/Database/MessageReporter.php
new file mode 100644
index 0000000..a961cda
--- /dev/null
+++ b/Database/Database/MessageReporter.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Wikibase\Database;
+
+/**
+ * Interface for objects that can report messages.
+ *
+ * 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
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+interface MessageReporter {
+
+ /**
+ * @param string $message
+ */
+ public function reportMessage( $message );
+
+}
diff --git a/Database/Database/TableBuilder.php
b/Database/Database/TableBuilder.php
index 5cdd5c6..d0876cc 100644
--- a/Database/Database/TableBuilder.php
+++ b/Database/Database/TableBuilder.php
@@ -2,8 +2,6 @@
namespace Wikibase\Database;
-use MessageReporter;
-
/**
* Object that can create a table in a database given a table definition.
*
diff --git a/Database/Database/TableDefinition.php
b/Database/Database/TableDefinition.php
index cbbedf1..8f95da7 100644
--- a/Database/Database/TableDefinition.php
+++ b/Database/Database/TableDefinition.php
@@ -5,7 +5,7 @@
use InvalidArgumentException;
/**
- * Definition of a database table.
+ * Definition of a database table. Immutable.
*
* 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
@@ -30,7 +30,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class TableDefinition implements \Immutable {
+class TableDefinition {
/**
* @since 0.1
diff --git a/Database/dependencies.txt b/Database/dependencies.txt
index 647a1dc..b84fed0 100644
--- a/Database/dependencies.txt
+++ b/Database/dependencies.txt
@@ -1,6 +1,5 @@
The Wikibase Database component is dependent on:
-* MediaWiki 1.21 or later
-* WikibaseLib (MessageReporter, DBConnectionProvider)
+* MediaWiki 1.21 or later (only when making use of the MediaWikiQueryInterface
implementation of QueryInterface)
And nothing else.
\ No newline at end of file
diff --git a/Database/phpunit.xml.dist b/Database/phpunit.xml.dist
new file mode 100644
index 0000000..8f2afd3
--- /dev/null
+++ b/Database/phpunit.xml.dist
@@ -0,0 +1,26 @@
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ bootstrap="tests/bootstrap.php"
+ cacheTokens="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="false"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false"
+ strict="true"
+ verbose="true">
+ <testsuites>
+ <testsuite name="WikibaseDatabaseStandalone">
+ <directory>tests/phpunit</directory>
+ <exclude>tests/phpunit/MWDB</exclude>
+ <exclude>tests/phpunit/MediaWikiQueryInterfaceTest.php</exclude>
+ </testsuite>
+ <testsuite name="WikibaseDatabaseMediaWiki">
+ <directory>tests/phpunit/MWDB</directory>
+ <file>tests/phpunit/MediaWikiQueryInterfaceTest.php</file>
+ </testsuite>
+ </testsuites>
+</phpunit>
diff --git a/Database/tests/bootstrap.php b/Database/tests/bootstrap.php
new file mode 100644
index 0000000..185a4e6
--- /dev/null
+++ b/Database/tests/bootstrap.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * PHPUnit test bootstrap file for the Wikibase Database component.
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup WikibaseDatabase
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+
+require_once( __DIR__ . '/../Database.php' );
+
+require_once( __DIR__ . '/testLoader.php' );
diff --git a/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
b/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
index d4f6666..5ef2f9b 100644
--- a/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
+++ b/Database/tests/phpunit/MWDB/ExtendedMySQLAbstractionTest.php
@@ -39,7 +39,7 @@
class ExtendedMySQLAbstractionTest extends ExtendedAbstractionTest {
protected function setUp() {
- if ( wfGetDB( DB_SLAVE )->getType() !== 'mysql' ) {
+ if ( !function_exists( 'wfGetDB' ) || wfGetDB( DB_SLAVE
)->getType() !== 'mysql' ) {
$this->markTestSkipped( 'Can only run the
ExtendedMySQLAbstractionTest when MediaWiki is using MySQL' );
}
diff --git a/Database/tests/phpunit/TableBuilderTest.php
b/Database/tests/phpunit/TableBuilderTest.php
index 343491e..481c8ba 100644
--- a/Database/tests/phpunit/TableBuilderTest.php
+++ b/Database/tests/phpunit/TableBuilderTest.php
@@ -5,7 +5,6 @@
use Wikibase\Database\TableBuilder;
use Wikibase\Database\FieldDefinition;
use Wikibase\Database\TableDefinition;
-use NullMessageReporter;
/**
* @covers Wikibase\Database\TableBuilder
@@ -48,7 +47,7 @@
array( new FieldDefinition( 'foo',
FieldDefinition::TYPE_TEXT ) )
);
- $reporter = new NullMessageReporter();
+ $reporter = $this->getMock( 'Wikibase\Database\MessageReporter'
);
$queryInterface = $this->getMock(
'Wikibase\Database\QueryInterface' );
diff --git a/Database/tests/testLoader.php b/Database/tests/testLoader.php
new file mode 100644
index 0000000..5ed1f58
--- /dev/null
+++ b/Database/tests/testLoader.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Test class autoloader for the Wikibase Database component.
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup WikibaseDatabase
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+
+spl_autoload_register( function ( $className ) {
+ $className = ltrim( $className, '\\' );
+ $fileName = '';
+ $namespace = '';
+
+ if ( $lastNsPos = strripos( $className, '\\') ) {
+ $namespace = substr( $className, 0, $lastNsPos );
+ $className = substr( $className, $lastNsPos + 1 );
+ $fileName = str_replace( '\\', '/', $namespace ) . '/';
+ }
+
+ $fileName .= str_replace( '_', '/', $className ) . '.php';
+
+ $namespaceSegments = explode( '\\', $namespace );
+
+ $inTestNamespace = count( $namespaceSegments ) > 2
+ && $namespaceSegments[0] === 'Wikibase'
+ && $namespaceSegments[1] === 'Test'
+ && $namespaceSegments[2] === 'Database';
+
+ if ( $inTestNamespace ) {
+ $pathParts = explode( '/', $fileName );
+ array_shift( $pathParts );
+ array_shift( $pathParts );
+ array_shift( $pathParts );
+ $fileName = implode( '/', $pathParts );
+
+ require_once __DIR__ . '/phpunit/' . $fileName;
+ }
+} );
--
To view, visit https://gerrit.wikimedia.org/r/63664
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ice733240915539418c272385293ac59929a74361
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Anja Jentzsch <[email protected]>
Gerrit-Reviewer: Ataherivand <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Lydia Pintscher <[email protected]>
Gerrit-Reviewer: Markus Kroetzsch <[email protected]>
Gerrit-Reviewer: Nikola Smolenski <[email protected]>
Gerrit-Reviewer: Silke Meyer <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits