*/
private function getMockLoadBalancer(
$mockDb,
- $expectedConnectionType = null,
- $readOnlyReason = false
+ $expectedConnectionType = null
) {
$mock = $this->getMockBuilder( LoadBalancer::class )
->disableOriginalConstructor()
->method( 'getConnectionRef' )
->will( $this->returnValue( $mockDb ) );
}
- $mock->expects( $this->any() )
- ->method( 'getReadOnlyReason' )
- ->will( $this->returnValue( $readOnlyReason ) );
return $mock;
}
->getMock();
$mock->expects( $this->any() )
->method( 'makeKey' )
- ->will( $this->returnCallback( function() {
+ ->will( $this->returnCallback( function () {
return implode( ':', func_get_args() );
} ) );
return $mock;
}
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|ReadOnlyMode
+ */
+ private function getMockReadOnlyMode( $readOnly = false ) {
+ $mock = $this->getMockBuilder( ReadOnlyMode::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'isReadOnly' )
+ ->will( $this->returnValue( $readOnly ) );
+ return $mock;
+ }
+
/**
* @param int $id
* @return PHPUnit_Framework_MockObject_MockObject|User
return $fakeRow;
}
- private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache ) {
+ private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache,
+ ReadOnlyMode $readOnlyMode
+ ) {
return new WatchedItemStore(
$loadBalancer,
- $cache
+ $cache,
+ $readOnlyMode
);
}
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 12, $store->countWatchedItems( $user ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 7, $store->countWatchers( $titleValue ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
->will( $this->returnValue( 7 ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 7, $store->countVisitingWatchers( $titleValue, '111' ) );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->exactly( 2 * 3 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 3 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->any() )
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$mockDb = $this->getMockDb();
$mockDb->expects( $this->exactly( 2 * 3 ) )
->method( 'addQuotes' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return "'$value'";
} ) );
$mockDb->expects( $this->exactly( 3 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->any() )
$this->isType( 'array' ),
$this->isType( 'int' )
)
- ->will( $this->returnCallback( function( $a, $conj ) {
+ ->will( $this->returnCallback( function ( $a, $conj ) {
$sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
- return join( $sqlConj, array_map( function( $s ) {
+ return join( $sqlConj, array_map( function ( $s ) {
return '(' . $s . ')';
}, $a
) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 9, $store->countUnreadNotifications( $user ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertSame(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$store->duplicateEntry(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateEntry(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateAllAssociatedEntries(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateAllAssociatedEntries(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->addWatch(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->addWatch(
public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $this->getMockDb(), null, 'Some Reason' ),
- $this->getMockCache()
+ $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode( true )
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$mockUser = $this->getMockNonAnonUserWithId( 1 );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItem = $store->loadWatchedItem(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItem = $store->getWatchedItem(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$user = $this->getMockNonAnonUserWithId( 1 );
$store = $this->newWatchedItemStore(
$mockLoadBalancer,
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItems = $store->getWatchedItemsForUser(
public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $this->getMockDb() ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->setExpectedException( 'InvalidArgumentException' );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
- $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
+ $mockCallback = function ( $callable ) use ( &$callableCallCounter ) {
$callableCallCounter++;
$this->assertInternalType( 'callable', $callable );
};
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
- $mockCallback = function( $callable ) use ( &$callableCallCounter ) {
+ $mockCallback = function ( $callable ) use ( &$callableCallCounter ) {
$callableCallCounter++;
$this->assertInternalType( 'callable', $callable );
};
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$callableCallCounter = 0;
$scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$callableCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$callableCallCounter, $title, $user ) {
$callableCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === null;
}
);
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time !== null && $time > '20151212010101';
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$callableCallCounter = 0;
$scopedOverride = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$callableCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$callableCallCounter, $title, $user ) {
$callableCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === null;
}
);
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === '30151212010101';
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
$scopedOverrideDeferred = $store->overrideDeferredUpdatesAddCallableUpdateCallback(
- function( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
+ function ( $callable ) use ( &$addUpdateCallCounter, $title, $user ) {
$addUpdateCallCounter++;
$this->verifyCallbackJob(
$callable,
$title,
$user->getId(),
- function( $time ) {
+ function ( $time ) {
return $time === false;
}
);
$getTimestampCallCounter = 0;
$scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
+ function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
$getTimestampCallCounter++;
$this->assertEquals( $title, $titleParam );
$this->assertEquals( $oldid, $oldidParam );
public function testSetNotificationTimestampsForUser_anonUser() {
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $this->getMockDb() ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertFalse( $store->setNotificationTimestampsForUser( $this->getAnonUser(), '' ) );
}
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 0 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
->will( $this->returnValue( true ) );
$mockDb->expects( $this->exactly( 1 ) )
->method( 'timestamp' )
- ->will( $this->returnCallback( function( $value ) {
+ ->will( $this->returnCallback( function ( $value ) {
return 'TS' . $value . 'TS';
} ) );
$mockDb->expects( $this->once() )
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchers = $store->updateNotificationTimestamp(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// This will add the item to the cache