Jeroen De Dauw has submitted this change and it was merged.
Change subject: Fill gaps in unit tests
......................................................................
Fill gaps in unit tests
This completes the incomplete tests and
expands test coverage
Change-Id: I40c201a8df9aa13086939c32707b898f6342d7bf
---
M tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
M tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
M tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
M tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
M tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
M tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
M tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
M tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
M tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
M tests/phpunit/Schema/ReportingTableBuilderTest.php
10 files changed, 131 insertions(+), 25 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
b/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
index ae9bfe1..ac115b7 100644
--- a/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
+++ b/tests/phpunit/MediaWiki/MWTableBuilderBuilderTest.php
@@ -53,7 +53,20 @@
}
public function testUnsupportedDbType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported DB type' );
+ $this->setExpectedException( 'RuntimeException', 'Cannot build
a MediaWikiQueryInterface for database type' );
+
+ $connection = $this->getMock( 'DatabaseMysql' );
+ $connection->expects( $this->once() )
+ ->method( 'getType' )
+ ->will( $this->returnValue( 'foobar' ) );
+
+ $connectionProvider = $this->getMock(
'Wikibase\Database\DBConnectionProvider' );
+ $connectionProvider->expects( $this->atLeastOnce() )
+ ->method( 'getConnection' )
+ ->will( $this->returnValue( $connection ) );
+
+ $builder = new MWTableBuilderBuilder();
+ $builder->setConnection( $connectionProvider
)->getTableBuilder();
}
}
diff --git a/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
b/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
index 6c076fa..b86ae1b 100644
--- a/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
+++ b/tests/phpunit/MediaWiki/MWTableDefinitionReaderTest.php
@@ -51,7 +51,24 @@
}
public function testUnsupportedDbType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported DB type' );
+ $this->setExpectedException( 'RuntimeException', 'Cannot build
a TableDefinitionReader for database type' );
+
+ $connection = $this->getMock( 'DatabaseMysql' );
+ $connection->expects( $this->once() )
+ ->method( 'getType' )
+ ->will( $this->returnValue( 'foobar' ) );
+
+ $connectionProvider = $this->getMock(
'Wikibase\Database\DBConnectionProvider' );
+ $connectionProvider->expects( $this->atLeastOnce() )
+ ->method( 'getConnection' )
+ ->will( $this->returnValue( $connection ) );
+
+ $queryInterface = $this->getMockBuilder(
'Wikibase\Database\MediaWiki\MediaWikiQueryInterface' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $builder = new MWTableDefinitionReaderBuilder();
+ $builder->setConnection( $connectionProvider
)->getTableDefinitionReader( $queryInterface );
}
}
diff --git a/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
b/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
index 97606f7..ca4e986 100644
--- a/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
+++ b/tests/phpunit/MediaWiki/MediaWikiQueryInterfaceTest.php
@@ -340,7 +340,14 @@
}
public function testSelectFailure() {
- $this->markTestIncomplete( 'write test for
MediaWikiQueryInterface select SelectFailedException' );
+ $this->setExpectedException(
'Wikibase\Database\QueryInterface\SelectFailedException' );
+ $connection = $this->getMock( 'DatabaseMysql' );
+ $connection->expects( $this->once() )
+ ->method( 'select' )
+ ->will( $this->returnValue( 'FOOBAR' ) );
+
+ $queryInterface = new MediaWikiQueryInterface( new
DirectConnectionProvider( $connection ) );
+ $queryInterface->select( 'ham', array( 'egg' ), array( 'chips'
) );
}
}
diff --git a/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
b/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
index 2099fdd..b3a2f90 100644
--- a/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
+++ b/tests/phpunit/MySQL/MySQLFieldSqlBuilderTest.php
@@ -39,15 +39,21 @@
public function fieldAndSqlProvider() {
$argLists = array();
- //TODO testcase with type INTEGER
- //TODO testcase with type FLOAT
+ $argLists[] = array(
+ new FieldDefinition(
+ 'fieldName',
+ FieldDefinition::TYPE_INTEGER
+ ),
+ 'fieldName INT NULL'
+ );
$argLists[] = array(
new FieldDefinition(
'fieldName',
- FieldDefinition::TYPE_BOOLEAN
+ FieldDefinition::TYPE_FLOAT,
+ FieldDefinition::NOT_NULL
),
- 'fieldName TINYINT NULL'
+ 'fieldName FLOAT NOT NULL'
);
$argLists[] = array(
@@ -73,8 +79,10 @@
return $argLists;
}
- public function testUnsupportedType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported field type' );
+ public function testUnsupportedType() {
+ $this->setExpectedException( 'RuntimeException', 'does not
support db fields of type' );
+ $sqlBuilder = new MySQLFieldSqlBuilder( $this->getMock(
'Wikibase\Database\Escaper' ) );
+ $sqlBuilder->getFieldSQL( new FieldDefinition( 'fieldName',
'foobar' ) );
}
}
\ No newline at end of file
diff --git a/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
b/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
index 00bd151..c476522 100644
--- a/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
+++ b/tests/phpunit/MySQL/MySQLIndexSqlBuilderTest.php
@@ -67,8 +67,22 @@
return $argLists;
}
- public function testUnsupportedType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported index type' );
+ public function testUnsupportedType() {
+ $this->setExpectedException( 'RuntimeException', 'does not
support db indexes of type' );
+
+ $tableNameFormatter = $this->getMockBuilder(
'Wikibase\Database\MediaWiki\MediaWikiTableNameFormatter' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $indexDefinition = $this->getMockBuilder(
'Wikibase\Database\Schema\Definitions\IndexDefinition' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $indexDefinition->expects( $this->once() )
+ ->method( 'getType' )
+ ->will( $this->returnValue( 'foobar' ) );
+
+ $sqlBuilder = new MySQLIndexSqlBuilder( $tableNameFormatter );
+ $sqlBuilder->getIndexSQL( $indexDefinition, 'tableName' );
}
}
\ No newline at end of file
diff --git a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
index dbaac65..14e4ea9 100644
--- a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
+++ b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
@@ -20,7 +20,7 @@
$this->assertTrue( true );
}
- protected function newInstance( $results = array() ) {
+ protected function newInstance( $results = array(), $tableExists = true
) {
$mockQueryInterface = $this
->getMockBuilder(
'Wikibase\Database\MediaWiki\MediaWikiQueryInterface' )
->disableOriginalConstructor()
@@ -28,7 +28,7 @@
$mockQueryInterface->expects( $this->any() )
->method( 'tableExists' )
- ->will( $this->returnValue( true ) );
+ ->will( $this->returnValue( $tableExists ) );
foreach( $results as $key => $result ){
$mockQueryInterface->expects( $this->at( $key + 1 ) )
@@ -40,7 +40,9 @@
}
public function testReadNonExistentTable(){
- $this->markTestIncomplete( 'Test QueryInterfaceException on
reading non existant table' );
+ $this->setExpectedException(
'Wikibase\Database\QueryInterface\QueryInterfaceException' );
+ $reader = $this->newInstance( array(), false );
+ $reader->readDefinition( 'dbNametableName' );
}
/**
@@ -55,8 +57,6 @@
public function sqlAndDefinitionProvider() {
$argLists = array();
- //TODO test field type TYPE_BOOLEAN
- //TODO test field type TYPE_FLOAT
//TODO test case containing constraints PRIMARY & UNIQUE
$argLists[] = array(
@@ -65,6 +65,8 @@
(object)array( 'name' =>
'primaryField', 'type' => 'INT', 'cannull' => 'NO', 'defaultvalue' => null ),
(object)array( 'name' => 'textField',
'type' => 'BLOB', 'cannull' => 'YES', 'defaultvalue' => null ),
(object)array( 'name' => 'intField',
'type' => 'INT', 'cannull' => 'NO', 'defaultvalue' => 42 ),
+ (object)array( 'name' => 'boolField',
'type' => 'TINYINT', 'cannull' => 'YES', 'defaultvalue' => null ),
+ (object)array( 'name' => 'floatField',
'type' => 'FLOAT', 'cannull' => 'YES', 'defaultvalue' => null ),
),
//TODO test UNIQUE and PRIMARY keys
array( null ),
@@ -88,6 +90,14 @@
FieldDefinition::TYPE_INTEGER,
FieldDefinition::NOT_NULL, 42
),
+ new FieldDefinition(
+ 'boolField',
+ FieldDefinition::TYPE_BOOLEAN
+ ),
+ new FieldDefinition(
+ 'floatField',
+ FieldDefinition::TYPE_FLOAT
+ )
),
array(
new IndexDefinition(
diff --git a/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
b/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
index cf0b677..aa0a35d 100644
--- a/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
+++ b/tests/phpunit/SQLite/SQLiteFieldSqlBuilderTest.php
@@ -69,8 +69,10 @@
return $argLists;
}
- public function testUnsupportedType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported field type' );
+ public function testUnsupportedType() {
+ $this->setExpectedException( 'RuntimeException', 'does not
support db fields of type' );
+ $sqlBuilder = new SQLiteFieldSqlBuilder( $this->getMock(
'Wikibase\Database\Escaper' ) );
+ $sqlBuilder->getFieldSQL( new FieldDefinition( 'fieldName',
'foobar' ) );
}
}
\ No newline at end of file
diff --git a/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
b/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
index 002cf4d..16826e5 100644
--- a/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
+++ b/tests/phpunit/SQLite/SQLiteIndexSqlBuilderTest.php
@@ -57,8 +57,22 @@
return $argLists;
}
- public function testUnsupportedType(){
- $this->markTestIncomplete( 'Test RuntimeException on
unsupported index type' );
+ public function testUnsupportedType() {
+ $this->setExpectedException( 'RuntimeException', 'does not
support db indexes of type' );
+
+ $tableNameFormatter = $this->getMockBuilder(
'Wikibase\Database\MediaWiki\MediaWikiTableNameFormatter' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $indexDefinition = $this->getMockBuilder(
'Wikibase\Database\Schema\Definitions\IndexDefinition' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $indexDefinition->expects( $this->once() )
+ ->method( 'getType' )
+ ->will( $this->returnValue( 'foobar' ) );
+
+ $sqlBuilder = new SQLiteIndexSqlBuilder( $tableNameFormatter );
+ $sqlBuilder->getIndexSQL( $indexDefinition, 'tableName' );
}
}
\ No newline at end of file
diff --git a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
index c43136a..f3d5c17 100644
--- a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
@@ -20,7 +20,7 @@
$this->assertTrue( true );
}
- protected function newInstance( $results = array() ) {
+ protected function newInstance( $results = array(), $tableExists = true
) {
$mockQueryInterface = $this
->getMockBuilder(
'Wikibase\Database\MediaWiki\MediaWikiQueryInterface' )
->disableOriginalConstructor()
@@ -28,7 +28,7 @@
$mockQueryInterface->expects( $this->any() )
->method( 'tableExists' )
- ->will( $this->returnValue( true ) );
+ ->will( $this->returnValue( $tableExists ) );
foreach( $results as $key => $result ){
$mockQueryInterface->expects( $this->at( $key + 1 ) )
@@ -40,7 +40,9 @@
}
public function testReadNonExistentTable(){
- $this->markTestIncomplete( 'Test QueryInterfaceException on
reading non existant table' );
+ $this->setExpectedException(
'Wikibase\Database\QueryInterface\QueryInterfaceException' );
+ $reader = $this->newInstance( array(), false );
+ $reader->readDefinition( 'dbNametableName' );
}
/**
diff --git a/tests/phpunit/Schema/ReportingTableBuilderTest.php
b/tests/phpunit/Schema/ReportingTableBuilderTest.php
index b835afb..0bf5b9b 100644
--- a/tests/phpunit/Schema/ReportingTableBuilderTest.php
+++ b/tests/phpunit/Schema/ReportingTableBuilderTest.php
@@ -17,8 +17,6 @@
*/
class ReportingTableBuilderTest extends \PHPUnit_Framework_TestCase {
- //TODO test tableExists method
-
/**
* @dataProvider tableProvider
*/
@@ -137,4 +135,25 @@
$reportingBuilder->dropTable( $table->getName() );
}
+ /**
+ * @dataProvider tableExistsProvider
+ */
+ public function testTableExists( $tableExists ){
+ $innerBuilder = $this->getMock(
'Wikibase\Database\Schema\TableBuilder' );
+ $reporter = $this->getMock( 'Wikibase\Database\MessageReporter'
);
+
+ $innerBuilder->expects( $this->once() )
+ ->method( 'tableExists' )
+ ->will( $this->returnValue( $tableExists ) );
+
+ $reportingBuilder = new ReportingTableBuilder( $innerBuilder,
$reporter );
+ $this->assertEquals( $tableExists,
$reportingBuilder->tableExists( 'foo' ) );
+ }
+
+ public function tableExistsProvider(){
+ return array(
+ array( true ),
+ array( false )
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/89526
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I40c201a8df9aa13086939c32707b898f6342d7bf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits