Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92905
Change subject: Throw exception if no results are returned
......................................................................
Throw exception if no results are returned
Change-Id: I4928070b20e1b46ee7142e40f1429ac9a1216849
---
M src/SQLite/SQLiteTableDefinitionReader.php
M tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
2 files changed, 23 insertions(+), 20 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase
refs/changes/05/92905/1
diff --git a/src/SQLite/SQLiteTableDefinitionReader.php
b/src/SQLite/SQLiteTableDefinitionReader.php
index 5af3c0e..00cfaae 100644
--- a/src/SQLite/SQLiteTableDefinitionReader.php
+++ b/src/SQLite/SQLiteTableDefinitionReader.php
@@ -61,8 +61,11 @@
*/
private function getFields( $tableName ) {
$results = $this->doCreateQuery( $tableName );
- if( iterator_count( $results ) > 1 ){
- throw new SchemaReadingException( "More than one set of
fields returned for {$tableName}" );
+ if( iterator_count( $results ) !== 1 ) {
+ throw new SchemaReadingException(
+ "Incorrect number of CREATE TABLE sql results
returned for {$tableName}" .
+ "\nExpected 1, Got " . strval( iterator_count(
$results ) )
+ );
}
$fields = array();
@@ -83,25 +86,7 @@
}
}
}
- $this->throwExceptionIfNoFields( $fields, $tableName, $results
);
return $fields;
- }
-
- /**
- * @param array $fields
- * @param string $tableName
- * @param ResultIterator $results
- *
- * @throws SchemaReadingException
- */
- private function throwExceptionIfNoFields( $fields, $tableName,
$results ){
- if( count( $fields ) === 0 ){
- $message = "Failed to read any fields for table:
{$tableName} from sql: ";
- foreach( $results as $result ){
- $message .= "\n'" . $result->sql . "'";
- }
- throw new SchemaReadingException( $message );
- }
}
/**
diff --git a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
index c912a78..9979979 100644
--- a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
@@ -140,4 +140,22 @@
return $argLists;
}
+ /**
+ * @dataProvider incorrectSqlCountProvider
+ */
+ public function testExceptionOnWrongNumberOfResults( $results ) {
+ $this->setExpectedException(
'Wikibase\Database\Schema\SchemaReadingException' );
+ $reader = $this->newInstance( $results );
+ $reader->readDefinition( 'foo' );
+ }
+
+ public function incorrectSqlCountProvider() {
+ $argLists = array();
+
+ $argLists['0 results'] = array( array( array( ) ) );
+ $argLists['2 results'] = array( array( array( (object)array(
'sql' => '' ), (object)array( 'sql' => '' ) ) ) );
+
+ return $argLists;
+ }
+
}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/92905
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4928070b20e1b46ee7142e40f1429ac9a1216849
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits