* Tests for BatchRowUpdate and its components
*
* @group db
+ *
+ * @covers BatchRowUpdate
+ * @covers BatchRowIterator
+ * @covers BatchRowWriter
*/
class BatchRowUpdateTest extends MediaWikiTestCase {
$batchSize = 2;
$reader = new BatchRowIterator( $db, 'some_table', 'id_field', $batchSize );
- $response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function() {
+ $response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function () {
static $i = 0;
return [ 'id_field' => ++$i ];
} );
*/
public function testReaderGetPrimaryKey( $message, array $expected, array $row ) {
$reader = new BatchRowIterator( $this->mockDb(), 'some_table', array_keys( $expected ), 8675309 );
- $this->assertEquals( $expected, $reader->extractPrimaryKeys( (object) $row ), $message );
+ $this->assertEquals( $expected, $reader->extractPrimaryKeys( (object)$row ), $message );
}
public static function provider_readerSetFetchColumns() {
public function testReaderSelectConditionsMultiplePrimaryKeys(
$message, $expectedSecondIteration, $primaryKeys, $batchSize = 3
) {
- $results = $this->genSelectResult( $batchSize, $batchSize * 3, function() {
+ $results = $this->genSelectResult( $batchSize, $batchSize * 3, function () {
static $i = 0, $j = 100, $k = 1000;
return [ 'id_field' => ++$i, 'foo' => ++$j, 'bar' => ++$k ];
} );
->will( $this->consecutivelyReturnFromSelect( $retvals ) );
$db->expects( $this->any() )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'"; // not real quoting: doesn't matter in test
} ) );
for ( $i = 0; $i < $numRows; $i += $batchSize ) {
$rows = [];
for ( $j = 0; $j < $batchSize && $i + $j < $numRows; $j++ ) {
- $rows [] = (object) call_user_func( $rowGenerator );
+ $rows [] = (object)call_user_func( $rowGenerator );
}
$res[] = $rows;
}
protected function mockDb() {
// @TODO: mock from Database
// FIXME: the constructor normally sets mAtomicLevels and mSrvCache
- $databaseMysql = $this->getMockBuilder( 'DatabaseMysql' )
+ $databaseMysql = $this->getMockBuilder( 'DatabaseMysqli' )
->disableOriginalConstructor()
->getMock();
$databaseMysql->expects( $this->any() )