From: Kunal Mehta Date: Thu, 12 Apr 2018 19:51:10 +0000 (-0700) Subject: Make BatchRowUpdateTest compatible with PHPUnit 6 X-Git-Tag: 1.31.0-rc.0~94^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=414b703c5842ec47a7809ec039b499f0b0966bb2 Make BatchRowUpdateTest compatible with PHPUnit 6 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 --- diff --git a/tests/phpunit/includes/utils/BatchRowUpdateTest.php b/tests/phpunit/includes/utils/BatchRowUpdateTest.php index f06a35319e..52b143393f 100644 --- a/tests/phpunit/includes/utils/BatchRowUpdateTest.php +++ b/tests/phpunit/includes/utils/BatchRowUpdateTest.php @@ -12,7 +12,7 @@ class BatchRowUpdateTest extends MediaWikiTestCase { public function testWriterBasicFunctionality() { - $db = $this->mockDb(); + $db = $this->mockDb( [ 'update' ] ); $writer = new BatchRowWriter( $db, 'echo_event' ); $updates = [ @@ -36,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 ) { @@ -130,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 @@ -202,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 ) ); @@ -238,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( Wikimedia\Rdbms\DatabaseMysqli::class ) ->disableOriginalConstructor() + ->setMethods( array_merge( [ 'isOpen', 'getApproximateLagStatus' ], $methods ) ) ->getMock(); $databaseMysql->expects( $this->any() ) ->method( 'isOpen' )