<?php
use MediaWiki\Linker\LinkTarget;
+use Wikimedia\Rdbms\LBFactory;
use Wikimedia\Rdbms\LoadBalancer;
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()
);
"(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
'))))' .
') OR ((wl_namespace = 1) AND (' .
- "(((wl_title = 'AnotherDbKey') AND (".
+ "(((wl_title = 'AnotherDbKey') AND (" .
"(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
')))))';
$mockDb->expects( $this->once() )
$mockCache->expects( $this->never() )->method( 'delete' );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
"(wl_notificationtimestamp >= 'TS111TS') OR (wl_notificationtimestamp IS NULL)" .
'))))' .
') OR ((wl_namespace = 1) AND (' .
- "(((wl_title = 'AnotherDbKey') AND (".
+ "(((wl_title = 'AnotherDbKey') AND (" .
"(wl_notificationtimestamp >= 'TS123TS') OR (wl_notificationtimestamp IS NULL)" .
'))))' .
') OR ' .
$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 )
);
]
);
+ $mockDb->expects( $this->once() )
+ ->method( 'affectedRows' )
+ ->willReturn( 2 );
+
$mockCache = $this->getMockCache();
$mockCache->expects( $this->exactly( 2 ) )
->method( 'delete' );
->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()
);
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->method( 'delete' )
- ->with(
- 'watchlist',
+ ->withConsecutive(
[
- 'wl_user' => 1,
- 'wl_namespace' => 0,
- 'wl_title' => 'SomeDbKey',
+ 'watchlist',
+ [
+ 'wl_user' => 1,
+ 'wl_namespace' => 0,
+ 'wl_title' => [ 'SomeDbKey' ],
+ ],
+ ],
+ [
+ 'watchlist',
+ [
+ 'wl_user' => 1,
+ 'wl_namespace' => 1,
+ 'wl_title' => [ 'SomeDbKey' ],
+ ]
]
);
- $mockDb->expects( $this->once() )
+ $mockDb->expects( $this->exactly( 1 ) )
->method( 'affectedRows' )
- ->will( $this->returnValue( 1 ) );
+ ->willReturn( 2 );
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->once() )
->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->withConsecutive(
+ [ '0:SomeDbKey:1' ],
+ [ '1:SomeDbKey:1' ]
+ );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
+ $titleValue = new TitleValue( 0, 'SomeDbKey' );
$this->assertTrue(
$store->removeWatch(
$this->getMockNonAnonUserWithId( 1 ),
- new TitleValue( 0, 'SomeDbKey' )
+ Title::newFromTitleValue( $titleValue )
)
);
}
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->method( 'delete' )
- ->with(
- 'watchlist',
+ ->withConsecutive(
[
- 'wl_user' => 1,
- 'wl_namespace' => 0,
- 'wl_title' => 'SomeDbKey',
+ 'watchlist',
+ [
+ 'wl_user' => 1,
+ 'wl_namespace' => 0,
+ 'wl_title' => [ 'SomeDbKey' ],
+ ]
+ ],
+ [
+ 'watchlist',
+ [
+ 'wl_user' => 1,
+ 'wl_namespace' => 1,
+ 'wl_title' => [ 'SomeDbKey' ],
+ ]
]
);
+
$mockDb->expects( $this->once() )
->method( 'affectedRows' )
- ->will( $this->returnValue( 0 ) );
+ ->willReturn( 0 );
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->once() )
->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->withConsecutive(
+ [ '0:SomeDbKey:1' ],
+ [ '1:SomeDbKey:1' ]
+ );
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockLBFactory( $mockDb ),
$mockCache,
$this->getMockReadOnlyMode()
);
+ $titleValue = new TitleValue( 0, 'SomeDbKey' );
$this->assertFalse(
$store->removeWatch(
$this->getMockNonAnonUserWithId( 1 ),
- new TitleValue( 0, 'SomeDbKey' )
+ Title::newFromTitleValue( $titleValue )
)
);
}
->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()
);