summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
54d50ef)
Explicitly declare all the methods that will be mocked. Also
testReaderBasicIterate needs to mock addQuotes as well, so use the
mockDbConsecutiveSelect() function that already takes care of that.
Change-Id: Ic02253cf25758124f320d0b46e0b1d43195c4bc0
class BatchRowUpdateTest extends MediaWikiTestCase {
public function testWriterBasicFunctionality() {
class BatchRowUpdateTest extends MediaWikiTestCase {
public function testWriterBasicFunctionality() {
+ $db = $this->mockDb( [ 'update' ] );
$writer = new BatchRowWriter( $db, 'echo_event' );
$updates = [
$writer = new BatchRowWriter( $db, 'echo_event' );
$updates = [
}
public function testReaderBasicIterate() {
}
public function testReaderBasicIterate() {
- $reader = new BatchRowIterator( $db, 'some_table', 'id_field', $batchSize );
-
$response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function () {
static $i = 0;
return [ 'id_field' => ++$i ];
} );
$response = $this->genSelectResult( $batchSize, /*numRows*/ 5, function () {
static $i = 0;
return [ 'id_field' => ++$i ];
} );
- $db->expects( $this->exactly( count( $response ) ) )
- ->method( 'select' )
- ->will( $this->consecutivelyReturnFromSelect( $response ) );
+ $db = $this->mockDbConsecutiveSelect( $response );
+ $reader = new BatchRowIterator( $db, 'some_table', 'id_field', $batchSize );
$pos = 0;
foreach ( $reader as $rows ) {
$pos = 0;
foreach ( $reader as $rows ) {
public function testReaderSetFetchColumns(
$message, array $columns, array $primaryKeys, array $fetchColumns
) {
public function testReaderSetFetchColumns(
$message, array $columns, array $primaryKeys, array $fetchColumns
) {
+ $db = $this->mockDb( [ 'select' ] );
$db->expects( $this->once() )
->method( 'select' )
// only testing second parameter of Database::select
$db->expects( $this->once() )
->method( 'select' )
// only testing second parameter of Database::select
}
protected function mockDbConsecutiveSelect( array $retvals ) {
}
protected function mockDbConsecutiveSelect( array $retvals ) {
+ $db = $this->mockDb( [ 'select', 'addQuotes' ] );
$db->expects( $this->any() )
->method( 'select' )
->will( $this->consecutivelyReturnFromSelect( $retvals ) );
$db->expects( $this->any() )
->method( 'select' )
->will( $this->consecutivelyReturnFromSelect( $retvals ) );
- protected function mockDb() {
+ protected function mockDb( $methods = [] ) {
// @TODO: mock from Database
// FIXME: the constructor normally sets mAtomicLevels and mSrvCache
$databaseMysql = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class )
->disableOriginalConstructor()
// @TODO: mock from Database
// FIXME: the constructor normally sets mAtomicLevels and mSrvCache
$databaseMysql = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class )
->disableOriginalConstructor()
+ ->setMethods( array_merge( [ 'isOpen', 'getApproximateLagStatus' ], $methods ) )
->getMock();
$databaseMysql->expects( $this->any() )
->method( 'isOpen' )
->getMock();
$databaseMysql->expects( $this->any() )
->method( 'isOpen' )