[MediaWiki-commits] [Gerrit] Have insert in QueryInterface throw an exception rather then... - change (mediawiki...Wikibase)
Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/64940 Change subject: Have insert in QueryInterface throw an exception rather then returning a boolean .. Have insert in QueryInterface throw an exception rather then returning a boolean Change-Id: I244983421b62e78658bfd726e704922ec68646f4 --- M Database/includes/MediaWikiQueryInterface.php M Database/includes/QueryInterface.php M Database/tests/phpunit/MediaWikiQueryInterfaceTest.php 3 files changed, 34 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/40/64940/1 diff --git a/Database/includes/MediaWikiQueryInterface.php b/Database/includes/MediaWikiQueryInterface.php index 306da96..d0c0026 100644 --- a/Database/includes/MediaWikiQueryInterface.php +++ b/Database/includes/MediaWikiQueryInterface.php @@ -113,14 +113,18 @@ * @param string $tableName * @param array $values * -* @return boolean Success indicator +* @throws InsertFailedException */ public function insert( $tableName, array $values ) { - return $this-getDB()-insert( + $success = $this-getDB()-insert( $tableName, $values, __METHOD__ ) !== false; + + if ( !$success ) { + throw new InsertFailedException( $tableName, $values ); + } } /** diff --git a/Database/includes/QueryInterface.php b/Database/includes/QueryInterface.php index add6206..647c205 100644 --- a/Database/includes/QueryInterface.php +++ b/Database/includes/QueryInterface.php @@ -74,8 +74,7 @@ * @param string $tableName * @param array $values * -* @return boolean Success indicator -* TODO: change to exception +* @throws InsertFailedException */ public function insert( $tableName, array $values ); diff --git a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php index 0041288..94ee771 100644 --- a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php +++ b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php @@ -202,7 +202,33 @@ -with( $this-equalTo( $tableName ), $this-equalTo( $fieldValues ) - ); + ) + -will( $this-returnValue( true ) ); + + $queryInterface-insert( + $tableName, + $fieldValues + ); + } + + /** +* @dataProvider insertProvider +*/ + public function testInsertFailure( $tableName, array $fieldValues ) { + $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( 'insert' ) + -will( $this-returnValue( false ) ); + + $this-setExpectedException( '\Wikibase\Database\InsertFailedException' ); $queryInterface-insert( $tableName, -- To view, visit https://gerrit.wikimedia.org/r/64940 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I244983421b62e78658bfd726e704922ec68646f4 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
[MediaWiki-commits] [Gerrit] Have insert in QueryInterface throw an exception rather then... - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Have insert in QueryInterface throw an exception rather then returning a boolean .. Have insert in QueryInterface throw an exception rather then returning a boolean Change-Id: I244983421b62e78658bfd726e704922ec68646f4 --- M Database/includes/MediaWikiQueryInterface.php M Database/includes/QueryInterface.php M Database/tests/phpunit/MediaWikiQueryInterfaceTest.php 3 files changed, 34 insertions(+), 5 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 306da96..d0c0026 100644 --- a/Database/includes/MediaWikiQueryInterface.php +++ b/Database/includes/MediaWikiQueryInterface.php @@ -113,14 +113,18 @@ * @param string $tableName * @param array $values * -* @return boolean Success indicator +* @throws InsertFailedException */ public function insert( $tableName, array $values ) { - return $this-getDB()-insert( + $success = $this-getDB()-insert( $tableName, $values, __METHOD__ ) !== false; + + if ( !$success ) { + throw new InsertFailedException( $tableName, $values ); + } } /** diff --git a/Database/includes/QueryInterface.php b/Database/includes/QueryInterface.php index add6206..647c205 100644 --- a/Database/includes/QueryInterface.php +++ b/Database/includes/QueryInterface.php @@ -74,8 +74,7 @@ * @param string $tableName * @param array $values * -* @return boolean Success indicator -* TODO: change to exception +* @throws InsertFailedException */ public function insert( $tableName, array $values ); diff --git a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php index 0041288..94ee771 100644 --- a/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php +++ b/Database/tests/phpunit/MediaWikiQueryInterfaceTest.php @@ -202,7 +202,33 @@ -with( $this-equalTo( $tableName ), $this-equalTo( $fieldValues ) - ); + ) + -will( $this-returnValue( true ) ); + + $queryInterface-insert( + $tableName, + $fieldValues + ); + } + + /** +* @dataProvider insertProvider +*/ + public function testInsertFailure( $tableName, array $fieldValues ) { + $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( 'insert' ) + -will( $this-returnValue( false ) ); + + $this-setExpectedException( '\Wikibase\Database\InsertFailedException' ); $queryInterface-insert( $tableName, -- To view, visit https://gerrit.wikimedia.org/r/64940 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I244983421b62e78658bfd726e704922ec68646f4 Gerrit-PatchSet: 1 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