*/
class DatabaseSQLTest extends MediaWikiTestCase {
+ /**
+ * @var DatabaseTestHelper
+ */
private $database;
protected function setUp() {
/**
* @dataProvider provideSelect
+ * @covers DatabaseBase::select
*/
- function testSelect( $sql, $sqlText ) {
+ public function testSelect( $sql, $sqlText ) {
$this->database->select(
$sql['tables'],
$sql['fields'],
/**
* @dataProvider provideUpdate
+ * @covers DatabaseBase::update
*/
- function testUpdate( $sql, $sqlText ) {
+ public function testUpdate( $sql, $sqlText ) {
$this->database->update(
$sql['table'],
$sql['values'],
/**
* @dataProvider provideDelete
+ * @covers DatabaseBase::delete
*/
- function testDelete( $sql, $sqlText ) {
+ public function testDelete( $sql, $sqlText ) {
$this->database->delete(
$sql['table'],
$sql['conds'],
);
}
+ /**
+ * @dataProvider provideUpsert
+ * @covers DatabaseBase::upsert
+ */
+ public function testUpsert( $sql, $sqlText ) {
+ $this->database->upsert(
+ $sql['table'],
+ $sql['rows'],
+ $sql['uniqueIndexes'],
+ $sql['set'],
+ __METHOD__
+ );
+ $this->assertLastSql( $sqlText );
+ }
+
+ public static function provideUpsert() {
+ return array(
+ array(
+ array(
+ 'table' => 'upsert_table',
+ 'rows' => array( 'field' => 'text', 'field2' => 'text2' ),
+ 'uniqueIndexes' => array( 'field' ),
+ 'set' => array( 'field' => 'set' ),
+ ),
+ "BEGIN; " .
+ "UPDATE upsert_table " .
+ "SET field = 'set' " .
+ "WHERE ((field = 'text')); " .
+ "INSERT IGNORE INTO upsert_table " .
+ "(field,field2) " .
+ "VALUES ('text','text2'); " .
+ "COMMIT"
+ ),
+ );
+ }
+
/**
* @dataProvider provideDeleteJoin
+ * @covers DatabaseBase::deleteJoin
*/
- function testDeleteJoin( $sql, $sqlText ) {
+ public function testDeleteJoin( $sql, $sqlText ) {
$this->database->deleteJoin(
$sql['delTable'],
$sql['joinTable'],
/**
* @dataProvider provideInsert
+ * @covers DatabaseBase::insert
*/
- function testInsert( $sql, $sqlText ) {
+ public function testInsert( $sql, $sqlText ) {
$this->database->insert(
$sql['table'],
$sql['rows'],
/**
* @dataProvider provideInsertSelect
+ * @covers DatabaseBase::insertSelect
*/
- function testInsertSelect( $sql, $sqlText ) {
+ public function testInsertSelect( $sql, $sqlText ) {
$this->database->insertSelect(
$sql['destTable'],
$sql['srcTable'],
/**
* @dataProvider provideReplace
+ * @covers DatabaseBase::replace
*/
- function testReplace( $sql, $sqlText ) {
+ public function testReplace( $sql, $sqlText ) {
$this->database->replace(
$sql['table'],
$sql['uniqueIndexes'],
/**
* @dataProvider provideNativeReplace
+ * @covers DatabaseBase::nativeReplace
*/
- function testNativeReplace( $sql, $sqlText ) {
+ public function testNativeReplace( $sql, $sqlText ) {
$this->database->nativeReplace(
$sql['table'],
$sql['rows'],
/**
* @dataProvider provideConditional
+ * @covers DatabaseBase::conditional
*/
- function testConditional( $sql, $sqlText ) {
+ public function testConditional( $sql, $sqlText ) {
$this->assertEquals( trim( $this->database->conditional(
$sql['conds'],
$sql['true'],
/**
* @dataProvider provideBuildConcat
+ * @covers DatabaseBase::buildConcat
*/
- function testBuildConcat( $stringList, $sqlText ) {
+ public function testBuildConcat( $stringList, $sqlText ) {
$this->assertEquals( trim( $this->database->buildConcat(
$stringList
) ), $sqlText );
/**
* @dataProvider provideBuildLike
+ * @covers DatabaseBase::buildLike
*/
- function testBuildLike( $array, $sqlText ) {
+ public function testBuildLike( $array, $sqlText ) {
$this->assertEquals( trim( $this->database->buildLike(
$array
) ), $sqlText );
/**
* @dataProvider provideUnionQueries
+ * @covers DatabaseBase::unionQueries
*/
- function testUnionQueries( $sql, $sqlText ) {
+ public function testUnionQueries( $sql, $sqlText ) {
$this->assertEquals( trim( $this->database->unionQueries(
$sql['sqls'],
$sql['all']
);
}
- function testTransactionCommit() {
+ /**
+ * @covers DatabaseBase::commit
+ */
+ public function testTransactionCommit() {
$this->database->begin( __METHOD__ );
$this->database->commit( __METHOD__ );
$this->assertLastSql( 'BEGIN; COMMIT' );
}
- function testTransactionRollback() {
+ /**
+ * @covers DatabaseBase::rollback
+ */
+ public function testTransactionRollback() {
$this->database->begin( __METHOD__ );
$this->database->rollback( __METHOD__ );
$this->assertLastSql( 'BEGIN; ROLLBACK' );
}
- function testDropTable() {
+ /**
+ * @covers DatabaseBase::dropTable
+ */
+ public function testDropTable() {
$this->database->setExistingTables( array( 'table' ) );
$this->database->dropTable( 'table', __METHOD__ );
$this->assertLastSql( 'DROP TABLE table' );
}
- function testDropNonExistingTable() {
+ /**
+ * @covers DatabaseBase::dropTable
+ */
+ public function testDropNonExistingTable() {
$this->assertFalse(
$this->database->dropTable( 'non_existing', __METHOD__ )
);