X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Futils%2FBatchRowUpdateTest.php;h=52b143393ffc4d310188bfaf0a1cf03767814267;hp=017e97d35767b0db5f9bd0ed2ab76b99f879cea2;hb=414b703c5842ec47a7809ec039b499f0b0966bb2;hpb=d56b46598d58f16eb8d7c8252083bbf3844e5430 diff --git a/tests/phpunit/includes/utils/BatchRowUpdateTest.php b/tests/phpunit/includes/utils/BatchRowUpdateTest.php index 017e97d357..52b143393f 100644 --- a/tests/phpunit/includes/utils/BatchRowUpdateTest.php +++ b/tests/phpunit/includes/utils/BatchRowUpdateTest.php @@ -4,11 +4,15 @@ * Tests for BatchRowUpdate and its components * * @group db + * + * @covers BatchRowUpdate + * @covers BatchRowIterator + * @covers BatchRowWriter */ class BatchRowUpdateTest extends MediaWikiTestCase { public function testWriterBasicFunctionality() { - $db = $this->mockDb(); + $db = $this->mockDb( [ 'update' ] ); $writer = new BatchRowWriter( $db, 'echo_event' ); $updates = [ @@ -32,17 +36,13 @@ class BatchRowUpdateTest extends MediaWikiTestCase { } public function testReaderBasicIterate() { - $db = $this->mockDb(); $batchSize = 2; - $reader = new BatchRowIterator( $db, 'some_table', 'id_field', $batchSize ); - $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 ) { @@ -126,7 +126,7 @@ class BatchRowUpdateTest extends MediaWikiTestCase { public function testReaderSetFetchColumns( $message, array $columns, array $primaryKeys, array $fetchColumns ) { - $db = $this->mockDb(); + $db = $this->mockDb( [ 'select' ] ); $db->expects( $this->once() ) ->method( 'select' ) // only testing second parameter of Database::select @@ -198,7 +198,7 @@ class BatchRowUpdateTest extends MediaWikiTestCase { } protected function mockDbConsecutiveSelect( array $retvals ) { - $db = $this->mockDb(); + $db = $this->mockDb( [ 'select', 'addQuotes' ] ); $db->expects( $this->any() ) ->method( 'select' ) ->will( $this->consecutivelyReturnFromSelect( $retvals ) ); @@ -234,11 +234,12 @@ class BatchRowUpdateTest extends MediaWikiTestCase { return $res; } - protected function mockDb() { + protected function mockDb( $methods = [] ) { // @TODO: mock from Database // FIXME: the constructor normally sets mAtomicLevels and mSrvCache - $databaseMysql = $this->getMockBuilder( 'DatabaseMysqli' ) + $databaseMysql = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class ) ->disableOriginalConstructor() + ->setMethods( array_merge( [ 'isOpen', 'getApproximateLagStatus' ], $methods ) ) ->getMock(); $databaseMysql->expects( $this->any() ) ->method( 'isOpen' )