Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64292
Change subject: Added SelectFailedException
......................................................................
Added SelectFailedException
Change-Id: Ied44503ca68e0156bb445787c64d958119149f8e
---
M Database/includes/MediaWikiQueryInterface.php
A Database/includes/SelectFailedException.php
A Database/tests/phpunit/SelectFailedExceptionTest.php
3 files changed, 132 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/92/64292/1
diff --git a/Database/includes/MediaWikiQueryInterface.php
b/Database/includes/MediaWikiQueryInterface.php
index b404cd0..8aeffca 100644
--- a/Database/includes/MediaWikiQueryInterface.php
+++ b/Database/includes/MediaWikiQueryInterface.php
@@ -178,6 +178,7 @@
* @param array $conditions
*
* @return ResultIterator
+ * @throws SelectFailedException
*/
public function select( $tableName, array $fields, array $conditions ) {
$selectionResult = $this->getDB()->select(
@@ -191,7 +192,7 @@
return new ResultIterator( iterator_to_array(
$selectionResult ) );
}
- // TODO: throw
+ throw new SelectFailedException( $tableName, $fields,
$conditions );
}
}
diff --git a/Database/includes/SelectFailedException.php
b/Database/includes/SelectFailedException.php
new file mode 100644
index 0000000..5ead691
--- /dev/null
+++ b/Database/includes/SelectFailedException.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Wikibase\Database;
+
+/**
+ * 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 WikibaseDatabase
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SelectFailedException extends QueryInterfaceException {
+
+ protected $tableName;
+ protected $fields;
+ protected $conditions;
+
+ public function __construct( $tableName, array $fields, array
$conditions, $message = '', \Exception $previous = null ) {
+ parent::__construct( $message, 0, $previous );
+
+ $this->tableName = $tableName;
+ $this->conditions = $conditions;
+ $this->fields = $fields;
+ }
+
+ /**
+ * @return string
+ */
+ public function getTableName() {
+ return $this->tableName;
+ }
+
+ /**
+ * @return array
+ */
+ public function getConditions() {
+ return $this->conditions;
+ }
+
+ /**
+ * @return array
+ */
+ public function getFields() {
+ return $this->fields;
+ }
+
+}
\ No newline at end of file
diff --git a/Database/tests/phpunit/SelectFailedExceptionTest.php
b/Database/tests/phpunit/SelectFailedExceptionTest.php
new file mode 100644
index 0000000..52a1462
--- /dev/null
+++ b/Database/tests/phpunit/SelectFailedExceptionTest.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Wikibase\Database\Tests;
+
+use Wikibase\Database\SelectFailedException;
+
+/**
+ * @covers Wikibase\Database\SelectFailedException 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 WikibaseDatabaseTest
+ *
+ * @group Wikibase
+ * @group WikibaseDatabase
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SelectFailedExceptionTest extends \PHPUnit_Framework_TestCase {
+
+ public function testConstructorWithOnlyRequiredArguments() {
+ $tableName = 'nyancats';
+ $fields = array( 'bar', 'baz', 'bah' );
+ $conditions = array( 'foo' => 42, 'awesome > 9000' );
+
+ $exception = new SelectFailedException( $tableName, $fields,
$conditions );
+
+ $this->assertEquals( $tableName, $exception->getTableName() );
+ $this->assertEquals( $fields, $exception->getFields() );
+ $this->assertEquals( $conditions, $exception->getConditions() );
+ }
+
+ public function testConstructorWithAllArguments() {
+ $tableName = 'users';
+ $fields = array( 'bar' );
+ $conditions = array( 'foo' => 42 );
+ $message = 'NyanData all the way accross the sky!';
+ $previous = new \Exception( 'Onoez!' );
+
+ $exception = new SelectFailedException( $tableName, $fields,
$conditions, $message, $previous );
+
+ $this->assertEquals( $tableName, $exception->getTableName() );
+ $this->assertEquals( $fields, $exception->getFields() );
+ $this->assertEquals( $conditions, $exception->getConditions() );
+ $this->assertEquals( $message, $exception->getMessage() );
+ $this->assertEquals( $previous, $exception->getPrevious() );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/64292
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied44503ca68e0156bb445787c64d958119149f8e
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