Change-Id: I93d9ed5f66297da7009d5b99aa9ed48e1b10582f
},
'WatchedItemQueryService' => function ( MediaWikiServices $services ) {
},
'WatchedItemQueryService' => function ( MediaWikiServices $services ) {
- return new WatchedItemQueryService( $services->getDBLoadBalancer() );
+ return new WatchedItemQueryService(
+ $services->getDBLoadBalancer(),
+ $services->getCommentStore()
+ );
},
'CryptRand' => function ( MediaWikiServices $services ) {
},
'CryptRand' => function ( MediaWikiServices $services ) {
/** @var CommentStore */
private $commentStore;
/** @var CommentStore */
private $commentStore;
- public function __construct( LoadBalancer $loadBalancer ) {
+ public function __construct(
+ LoadBalancer $loadBalancer,
+ CommentStore $commentStore
+ ) {
$this->loadBalancer = $loadBalancer;
$this->loadBalancer = $loadBalancer;
- $this->commentStore = CommentStore::getStore();
+ $this->commentStore = $commentStore;
+use Wikimedia\Rdbms\LoadBalancer;
use Wikimedia\TestingAccessWrapper;
/**
use Wikimedia\TestingAccessWrapper;
/**
use MediaWikiCoversValidator;
use MediaWikiCoversValidator;
- private function overrideCommentStore() {
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|CommentStore
+ */
+ private function getMockCommentStore() {
$mockStore = $this->getMockBuilder( CommentStore::class )
->disableOriginalConstructor()
->getMock();
$mockStore = $this->getMockBuilder( CommentStore::class )
->disableOriginalConstructor()
->getMock();
'fields' => [ 'commentstore' => 'field' ],
'joins' => [ 'commentstore' => 'join' ],
] );
'fields' => [ 'commentstore' => 'field' ],
'joins' => [ 'commentstore' => 'join' ],
] );
- $this->setService( 'CommentStore', $mockStore );
+ /**
+ * @param PHPUnit_Framework_MockObject_MockObject|Database $mockDb
+ * @return WatchedItemQueryService
+ */
+ private function newService( $mockDb ) {
+ return new WatchedItemQueryService(
+ $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockCommentStore()
+ );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$startFrom = null;
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$startFrom = null;
$startFrom = [ '20160203123456', 42 ];
} ) );
$startFrom = [ '20160203123456', 42 ];
} ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
TestingAccessWrapper::newFromObject( $queryService )->extensions = [ $mockExtension ];
$startFrom = null;
TestingAccessWrapper::newFromObject( $queryService )->extensions = [ $mockExtension ];
$startFrom = null;
array $expectedDbOptions,
array $expectedExtraJoinConds
) {
array $expectedDbOptions,
array $expectedExtraJoinConds
) {
- $this->overrideCommentStore();
-
$expectedTables = array_merge( [ 'recentchanges', 'watchlist', 'page' ], $expectedExtraTables );
$expectedFields = array_merge(
[
$expectedTables = array_merge( [ 'recentchanges', 'watchlist', 'page' ], $expectedExtraTables );
$expectedFields = array_merge(
[
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options, $startFrom );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options, $startFrom );
$user = $this->getMockNonAnonUserWithIdAndNoPatrolRights( 1 );
$user = $this->getMockNonAnonUserWithIdAndNoPatrolRights( 1 );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
$user,
[ 'filters' => [ $filtersOption ] ]
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
$user,
[ 'filters' => [ $filtersOption ] ]
->method( 'getType' )
->will( $this->returnValue( $dbType ) );
->method( 'getType' )
->will( $this->returnValue( $dbType ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options );
$user = $this->getMockNonAnonUserWithIdAndRestrictedPermissions( 1, $notAllowedAction );
$user = $this->getMockNonAnonUserWithIdAndRestrictedPermissions( 1, $notAllowedAction );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options );
$this->assertEmpty( $items );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options );
$this->assertEmpty( $items );
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, [ 'allRevisions' => true ] );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, [ 'allRevisions' => true ] );
$mockDb->expects( $this->never() )
->method( $this->anything() );
$mockDb->expects( $this->never() )
->method( $this->anything() );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage );
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsWithRecentChangeInfo(
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 );
$otherUser->expects( $this->once() )
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 );
$otherUser->expects( $this->once() )
$mockDb->expects( $this->never() )
->method( $this->anything() );
$mockDb->expects( $this->never() )
->method( $this->anything() );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 );
$otherUser->expects( $this->once() )
$user = $this->getMockUnrestrictedNonAnonUserWithId( 1 );
$otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 );
$otherUser->expects( $this->once() )
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$user = $this->getMockNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsForUser( $user );
$user = $this->getMockNonAnonUserWithId( 1 );
$items = $queryService->getWatchedItemsForUser( $user );
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$items = $queryService->getWatchedItemsForUser( $user, $options );
$this->assertEmpty( $items );
$items = $queryService->getWatchedItemsForUser( $user, $options );
$this->assertEmpty( $items );
)
->will( $this->returnValue( [] ) );
)
->will( $this->returnValue( [] ) );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$items = $queryService->getWatchedItemsForUser( $user, $options );
$this->assertEmpty( $items );
$items = $queryService->getWatchedItemsForUser( $user, $options );
$this->assertEmpty( $items );
array $options,
$expectedInExceptionMessage
) {
array $options,
$expectedInExceptionMessage
) {
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $this->getMockDb() ) );
+ $queryService = $this->newService( $this->getMockDb() );
$this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage );
$queryService->getWatchedItemsForUser( $this->getMockNonAnonUserWithId( 1 ), $options );
$this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage );
$queryService->getWatchedItemsForUser( $this->getMockNonAnonUserWithId( 1 ), $options );
$mockDb->expects( $this->never() )
->method( $this->anything() );
$mockDb->expects( $this->never() )
->method( $this->anything() );
- $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) );
+ $queryService = $this->newService( $mockDb );
$items = $queryService->getWatchedItemsForUser( $this->getMockAnonUser() );
$this->assertEmpty( $items );
$items = $queryService->getWatchedItemsForUser( $this->getMockAnonUser() );
$this->assertEmpty( $items );