<?php
use MediaWiki\Linker\LinkTarget;
use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\LBFactory;
use Wikimedia\ScopedCallback;
use Wikimedia\TestingAccessWrapper;
return $mock;
}
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|LBFactory
+ */
+ private function getMockLBFactory(
+ $mockDb,
+ $expectedConnectionType = null
+ ) {
+ $loadBalancer = $this->getMockLoadBalancer( $mockDb, $expectedConnectionType );
+ $mock = $this->getMockBuilder( LBFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getMainLB' )
+ ->will( $this->returnValue( $loadBalancer ) );
+ return $mock;
+ }
+
/**
* @return PHPUnit_Framework_MockObject_MockObject|HashBagOStuff
*/
return $fakeRow;
}
- private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache,
+ private function newWatchedItemStore( LBFactory $lbFactory, HashBagOStuff $cache,
ReadOnlyMode $readOnlyMode
) {
return new WatchedItemStore(
- $loadBalancer,
+ $lbFactory,
$cache,
$readOnlyMode,
1000
->with( 'RM-KEY' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:Some_Page:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockLBFactory( $this->getMockDb() ),
$this->getMockCache(),
$this->getMockReadOnlyMode( true )
);
->with( '1:Some_Page:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
);
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
);
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->will( $this->returnValue( $cachedItem ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->will( $this->returnValue( false ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'set' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
public function testGetWatchedItemsForUser_optionsAndEmptyResult( $forWrite, $dbType ) {
$mockDb = $this->getMockDb();
$mockCache = $this->getMockCache();
- $mockLoadBalancer = $this->getMockLoadBalancer( $mockDb, $dbType );
+ $mockLoadBalancer = $this->getMockLBFactory( $mockDb, $dbType );
$user = $this->getMockNonAnonUserWithId( 1 );
$mockDb->expects( $this->once() )
public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockLBFactory( $this->getMockDb() ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
);
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->will( $this->returnValue( false ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( $this->anything() );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeTitle:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
public function testSetNotificationTimestampsForUser_anonUser() {
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockLBFactory( $this->getMockDb() ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
} ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
} ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$this->getMockCache(),
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
->with( '0:SomeDbKey:1' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);