Denny Vrandecic has submitted this change and it was merged. Change subject: Added SelectFailedException ......................................................................
Added SelectFailedException Change-Id: Ied44503ca68e0156bb445787c64d958119149f8e --- M Database/includes/MediaWikiQueryInterface.php A Database/includes/SelectFailedException.php M Database/tests/phpunit/MediaWikiQueryInterfaceTest.php A Database/tests/phpunit/SelectFailedExceptionTest.php 4 files changed, 137 insertions(+), 2 deletions(-) Approvals: Denny Vrandecic: Looks good to me, approved jenkins-bot: Verified 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 < jeroended...@gmail.com > + */ +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/MediaWikiQueryInterfaceTest.php b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php index 08c9520..3e7aac4 100644 --- a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php +++ b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php @@ -339,13 +339,17 @@ $extendedAbstraction ); + $resultWrapper = $this->getMockBuilder( 'ResultWrapper' ) + ->disableOriginalConstructor()->getMock(); + $connection->expects( $this->once() ) ->method( 'select' ) ->with( $this->equalTo( $tableName ), $this->equalTo( $fields ), $this->equalTo( $conditions ) - ); + ) + ->will( $this->returnValue( $resultWrapper ) ); $queryInterface->select( $tableName, $fields, $conditions ); 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 < jeroended...@gmail.com > + */ +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: merged Gerrit-Change-Id: Ied44503ca68e0156bb445787c64d958119149f8e Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits