* @copyright © 2013 Wikimedia Foundation Inc.
*/
+use Wikimedia\Rdbms\TransactionProfiler;
+use Wikimedia\Rdbms\DatabaseDomain;
+
/**
* Fake class around abstract class so we can call concrete methods.
*/
class FakeDatabaseMysqlBase extends DatabaseMysqlBase {
- // From DatabaseBase
+ // From Database
function __construct() {
$this->profiler = new ProfilerStub( [] );
$this->trxProfiler = new TransactionProfiler();
}
- // From interface DatabaseType
function insertId() {
}
}
function getMockForViews() {
- $db = $this->getMockBuilder( 'DatabaseMysql' )
+ $db = $this->getMockBuilder( 'DatabaseMysqli' )
->disableOriginalConstructor()
->setMethods( [ 'fetchRow', 'query' ] )
->getMock();
$db->method( 'query' )
->with( $this->anything() )
- ->willReturn( null );
+ ->willReturn( new FakeResultWrapper( [
+ (object)[ 'Tables_in_' => 'view1' ],
+ (object)[ 'Tables_in_' => 'view2' ],
+ (object)[ 'Tables_in_' => 'myview' ]
+ ] ) );
- $db->method( 'fetchRow' )
- ->with( $this->anything() )
- ->will( $this->onConsecutiveCalls(
- [ 'Tables_in_' => 'view1' ],
- [ 'Tables_in_' => 'view2' ],
- [ 'Tables_in_' => 'myview' ],
- false # no more rows
- ) );
return $db;
}
/**
function testListviews() {
$db = $this->getMockForViews();
- // The first call populate an internal cache of views
- $this->assertEquals( [ 'view1', 'view2', 'myview' ],
- $db->listViews() );
$this->assertEquals( [ 'view1', 'view2', 'myview' ],
$db->listViews() );
$db->listViews( '' ) );
}
- /**
- * @covers DatabaseMysqlBase::isView
- * @dataProvider provideViewExistanceChecks
- */
- function testIsView( $isView, $viewName ) {
- $db = $this->getMockForViews();
-
- switch ( $isView ) {
- case true:
- $this->assertTrue( $db->isView( $viewName ),
- "$viewName should be considered a view" );
- break;
-
- case false:
- $this->assertFalse( $db->isView( $viewName ),
- "$viewName has not been defined as a view" );
- break;
- }
-
- }
-
- function provideViewExistanceChecks() {
- return [
- // format: whether it is a view, view name
- [ true, 'view1' ],
- [ true, 'view2' ],
- [ true, 'myview' ],
-
- [ false, 'user' ],
-
- [ false, 'view10' ],
- [ false, 'my' ],
- [ false, 'OH_MY_GOD' ], # they killed kenny!
- ];
- }
-
/**
* @dataProvider provideComparePositions
*/
* @dataProvider provideLagAmounts
*/
function testPtHeartbeat( $lag ) {
- $db = $this->getMockBuilder( 'DatabaseMysql' )
+ $db = $this->getMockBuilder( 'DatabaseMysqli' )
->disableOriginalConstructor()
->setMethods( [
'getLagDetectionMethod', 'getHeartbeatData', 'getMasterServerInfo' ] )