Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/64935
Change subject: update and delete methods in QueryInterface now throw exceptions rather then retruning a boolean ...................................................................... update and delete methods in QueryInterface now throw exceptions rather then retruning a boolean Change-Id: I08f665f1700381cdd30114d1cfd2bc02953922d8 --- M Database/includes/MediaWikiQueryInterface.php M Database/includes/QueryInterface.php M Database/tests/phpunit/MediaWikiQueryInterfaceTest.php 3 files changed, 67 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/35/64935/1 diff --git a/Database/includes/MediaWikiQueryInterface.php b/Database/includes/MediaWikiQueryInterface.php index 52bdf78..306da96 100644 --- a/Database/includes/MediaWikiQueryInterface.php +++ b/Database/includes/MediaWikiQueryInterface.php @@ -132,15 +132,19 @@ * @param array $values * @param array $conditions * - * @return boolean Success indicator + * @throws UpdateFailedException */ public function update( $tableName, array $values, array $conditions ) { - return $this->getDB()->update( + $success = $this->getDB()->update( $tableName, $values, $conditions, __METHOD__ ) !== false; + + if ( !$success ) { + throw new UpdateFailedException( $tableName, $values, $conditions ); + } } /** @@ -151,14 +155,18 @@ * @param string $tableName * @param array $conditions * - * @return boolean Success indicator + * @throws DeleteFailedException */ public function delete( $tableName, array $conditions ) { - return $this->getDB()->delete( + $success = $this->getDB()->delete( $tableName, $conditions, __METHOD__ ) !== false; + + if ( !$success ) { + throw new DeleteFailedException( $tableName, $conditions ); + } } /** diff --git a/Database/includes/QueryInterface.php b/Database/includes/QueryInterface.php index 79ffc8e..31bd3c9 100644 --- a/Database/includes/QueryInterface.php +++ b/Database/includes/QueryInterface.php @@ -74,6 +74,7 @@ * @param array $values * * @return boolean Success indicator + * TODO: change to exception */ public function insert( $tableName, array $values ); @@ -88,7 +89,7 @@ * @param array $values * @param array $conditions * - * @return boolean Success indicator + * @throws UpdateFailedException */ public function update( $tableName, array $values, array $conditions ); @@ -102,7 +103,7 @@ * @param string $tableName * @param array $conditions * - * @return boolean Success indicator + * @throw DeleteFailedException */ public function delete( $tableName, array $conditions ); diff --git a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php index 731551c..0041288 100644 --- a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php +++ b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php @@ -246,7 +246,34 @@ $this->equalTo( $tableName ), $this->equalTo( $newValues ), $this->equalTo( $conditions ) - ); + ) + ->will( $this->returnValue( true ) ); + + $queryInterface->update( + $tableName, + $newValues, + $conditions + ); + } + + /** + * @dataProvider updateProvider + */ + public function testUpdateFailure( $tableName, array $newValues, array $conditions ) { + $connection = $this->getMock( 'DatabaseMysql' ); + $extendedAbstraction = $this->getMockBuilder( '\Wikibase\Database\MWDB\ExtendedMySQLAbstraction' ) + ->disableOriginalConstructor()->getMock(); + + $queryInterface = new MediaWikiQueryInterface( + new DirectConnectionProvider( $connection ), + $extendedAbstraction + ); + + $connection->expects( $this->once() ) + ->method( 'update' ) + ->will( $this->returnValue( false ) ); + + $this->setExpectedException( '\Wikibase\Database\UpdateFailedException' ); $queryInterface->update( $tableName, @@ -312,7 +339,30 @@ ->with( $this->equalTo( $tableName ), $this->equalTo( $conditions ) - ); + ) + ->will( $this->returnValue( true ) ); + + $queryInterface->delete( $tableName, $conditions ); + } + + /** + * @dataProvider deleteProvider + */ + public function testDeleteFailure( $tableName, array $conditions ) { + $connection = $this->getMock( 'DatabaseMysql' ); + $extendedAbstraction = $this->getMockBuilder( '\Wikibase\Database\MWDB\ExtendedMySQLAbstraction' ) + ->disableOriginalConstructor()->getMock(); + + $queryInterface = new MediaWikiQueryInterface( + new DirectConnectionProvider( $connection ), + $extendedAbstraction + ); + + $connection->expects( $this->once() ) + ->method( 'delete' ) + ->will( $this->returnValue( false ) ); + + $this->setExpectedException( '\Wikibase\Database\DeleteFailedException' ); $queryInterface->delete( $tableName, $conditions ); } -- To view, visit https://gerrit.wikimedia.org/r/64935 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I08f665f1700381cdd30114d1cfd2bc02953922d8 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