Namespace LinkTarget under MediaWiki\Linker
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreUnitTest.php
index afde88c..d9fd4de 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+use MediaWiki\Linker\LinkTarget;
 
 /**
  * @author Addshore
@@ -17,7 +18,11 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
        /**
         * @return PHPUnit_Framework_MockObject_MockObject|LoadBalancer
         */
-       private function getMockLoadBalancer( $mockDb, $expectedConnectionType = null ) {
+       private function getMockLoadBalancer(
+               $mockDb,
+               $expectedConnectionType = null,
+               $readOnlyReason = false
+       ) {
                $mock = $this->getMockBuilder( LoadBalancer::class )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -33,7 +38,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                }
                $mock->expects( $this->any() )
                        ->method( 'getReadOnlyReason' )
-                       ->will( $this->returnValue( false ) );
+                       ->will( $this->returnValue( $readOnlyReason ) );
                return $mock;
        }
 
@@ -82,6 +87,13 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                return $fakeRow;
        }
 
+       private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache ) {
+               return new WatchedItemStore(
+                       $loadBalancer,
+                       $cache
+               );
+       }
+
        public function testGetDefaultInstance() {
                $instanceOne = WatchedItemStore::getDefaultInstance();
                $instanceTwo = WatchedItemStore::getDefaultInstance();
@@ -120,7 +132,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -150,7 +162,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -201,7 +213,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -267,7 +279,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -315,7 +327,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -394,7 +406,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -496,7 +508,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -549,7 +561,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -586,7 +598,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -620,7 +632,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -657,7 +669,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -687,7 +699,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        )
                        ->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $this->getMockCache()
                );
@@ -745,7 +757,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -791,7 +803,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -802,7 +814,20 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                );
        }
 
-       public function testDuplicateAllAssociatedEntries_somethingToDuplicate() {
+       public function provideLinkTargetPairs() {
+               return [
+                       [ Title::newFromText( 'Old_Title' ), Title::newFromText( 'New_Title' ) ],
+                       [ new TitleValue( 0, 'Old_Title' ),  new TitleValue( 0, 'New_Title' ) ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideLinkTargetPairs
+        */
+       public function testDuplicateAllAssociatedEntries_somethingToDuplicate(
+               LinkTarget $oldTarget,
+               LinkTarget $newTarget
+       ) {
                $fakeRows = [
                        $this->getFakeRow( [ 'wl_user' => 1, 'wl_notificationtimestamp' => '20151212010101' ] ),
                ];
@@ -817,8 +842,8 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                        'wl_notificationtimestamp',
                                ],
                                [
-                                       'wl_namespace' => 0,
-                                       'wl_title' => 'Old_Title',
+                                       'wl_namespace' => $oldTarget->getNamespace(),
+                                       'wl_title' => $oldTarget->getDBkey(),
                                ]
                        )
                        ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
@@ -830,8 +855,8 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                [
                                        [
                                                'wl_user' => 1,
-                                               'wl_namespace' => 0,
-                                               'wl_title' => 'New_Title',
+                                               'wl_namespace' => $newTarget->getNamespace(),
+                                               'wl_title' => $newTarget->getDBkey(),
                                                'wl_notificationtimestamp' => '20151212010101',
                                        ],
                                ],
@@ -846,8 +871,8 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                        'wl_notificationtimestamp',
                                ],
                                [
-                                       'wl_namespace' => 1,
-                                       'wl_title' => 'Old_Title',
+                                       'wl_namespace' => $oldTarget->getNamespace() + 1,
+                                       'wl_title' => $oldTarget->getDBkey(),
                                ]
                        )
                        ->will( $this->returnValue( new FakeResultWrapper( $fakeRows ) ) );
@@ -859,8 +884,8 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                [
                                        [
                                                'wl_user' => 1,
-                                               'wl_namespace' => 1,
-                                               'wl_title' => 'New_Title',
+                                               'wl_namespace' => $newTarget->getNamespace() + 1,
+                                               'wl_title' => $newTarget->getDBkey(),
                                                'wl_notificationtimestamp' => '20151212010101',
                                        ],
                                ],
@@ -871,14 +896,14 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
 
                $store->duplicateAllAssociatedEntries(
-                       Title::newFromText( 'Old_Title' ),
-                       Title::newFromText( 'New_Title' )
+                       $oldTarget,
+                       $newTarget
                );
        }
 
@@ -903,7 +928,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '0:Some_Page:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -923,7 +948,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -934,7 +959,21 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                );
        }
 
-       public function testAddWatchBatch_nonAnonymousUser() {
+       public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
+               $store = $this->newWatchedItemStore(
+                       $this->getMockLoadBalancer( $this->getMockDb(), null, 'Some Reason' ),
+                       $this->getMockCache()
+               );
+
+               $this->assertFalse(
+                       $store->addWatchBatchForUser(
+                               $this->getMockNonAnonUserWithId( 1 ),
+                               [ new TitleValue( 0, 'Some_Page' ), new TitleValue( 1, 'Some_Page' ) ]
+                       )
+               );
+       }
+
+       public function testAddWatchBatchForUser_nonAnonymousUser() {
                $mockDb = $this->getMockDb();
                $mockDb->expects( $this->once() )
                        ->method( 'insert' )
@@ -966,7 +1005,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '1:Some_Page:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -974,52 +1013,14 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockUser = $this->getMockNonAnonUserWithId( 1 );
 
                $this->assertTrue(
-                       $store->addWatchBatch(
-                               [
-                                       [ $mockUser, new TitleValue( 0, 'Some_Page' ) ],
-                                       [ $mockUser, new TitleValue( 1, 'Some_Page' ) ],
-                               ]
-                       )
-               );
-       }
-
-       public function testAddWatchBatch_anonymousUserCombinationsAreSkipped() {
-               $mockDb = $this->getMockDb();
-               $mockDb->expects( $this->once() )
-                       ->method( 'insert' )
-                       ->with(
-                               'watchlist',
-                               [
-                                       [
-                                               'wl_user' => 1,
-                                               'wl_namespace' => 0,
-                                               'wl_title' => 'Some_Page',
-                                               'wl_notificationtimestamp' => null,
-                                       ]
-                               ]
-                       );
-
-               $mockCache = $this->getMockCache();
-               $mockCache->expects( $this->once() )
-                       ->method( 'delete' )
-                       ->with( '0:Some_Page:1' );
-
-               $store = new WatchedItemStore(
-                       $this->getMockLoadBalancer( $mockDb ),
-                       $mockCache
-               );
-
-               $this->assertTrue(
-                       $store->addWatchBatch(
-                               [
-                                       [ $this->getMockNonAnonUserWithId( 1 ), new TitleValue( 0, 'Some_Page' ) ],
-                                       [ $this->getAnonUser(), new TitleValue( 0, 'Other_Page' ) ],
-                               ]
+                       $store->addWatchBatchForUser(
+                               $mockUser,
+                               [ new TitleValue( 0, 'Some_Page' ), new TitleValue( 1, 'Some_Page' ) ]
                        )
                );
        }
 
-       public function testAddWatchBatchReturnsFalse_whenOnlyGivenAnonymousUserCombinations() {
+       public function testAddWatchBatchForUser_anonymousUsersAreSkipped() {
                $mockDb = $this->getMockDb();
                $mockDb->expects( $this->never() )
                        ->method( 'insert' );
@@ -1028,23 +1029,21 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
 
-               $anonUser = $this->getAnonUser();
                $this->assertFalse(
-                       $store->addWatchBatch(
-                               [
-                                       [ $anonUser, new TitleValue( 0, 'Some_Page' ) ],
-                                       [ $anonUser, new TitleValue( 1, 'Other_Page' ) ],
-                               ]
+                       $store->addWatchBatchForUser(
+                               $this->getAnonUser(),
+                               [ new TitleValue( 0, 'Other_Page' ) ]
                        )
                );
        }
 
-       public function testAddWatchBatchReturnsFalse_whenGivenEmptyList() {
+       public function testAddWatchBatchReturnsTrue_whenGivenEmptyList() {
+               $user = $this->getMockNonAnonUserWithId( 1 );
                $mockDb = $this->getMockDb();
                $mockDb->expects( $this->never() )
                        ->method( 'insert' );
@@ -1053,13 +1052,13 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
 
-               $this->assertFalse(
-                       $store->addWatchBatch( [] )
+               $this->assertTrue(
+                       $store->addWatchBatchForUser( $user, [] )
                );
        }
 
@@ -1087,7 +1086,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                '0:SomeDbKey:1'
                        );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1121,7 +1120,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1143,7 +1142,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1178,7 +1177,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '0:SomeDbKey:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1213,7 +1212,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '0:SomeDbKey:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1236,7 +1235,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1280,7 +1279,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                '0:SomeDbKey:1'
                        );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1314,7 +1313,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        )
                        ->will( $this->returnValue( $cachedItem ) );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1351,7 +1350,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->with( '0:SomeDbKey:1' )
                        ->will( $this->returnValue( false ) );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1374,7 +1373,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1414,7 +1413,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'set' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1464,7 +1463,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        )
                        ->will( $this->returnValue( [] ) );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $mockLoadBalancer,
                        $mockCache
                );
@@ -1477,7 +1476,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
        }
 
        public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $this->getMockDb() ),
                        $this->getMockCache()
                );
@@ -1518,7 +1517,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                                '0:SomeDbKey:1'
                        );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1554,7 +1553,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->with( '0:SomeDbKey:1' )
                        ->will( $this->returnValue( false ) );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1577,7 +1576,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1644,7 +1643,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1694,7 +1693,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1755,7 +1754,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1795,7 +1794,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1821,7 +1820,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache = $this->getMockCache();
                $mockCache->expects( $this->never() )->method( $this->anything() );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1845,7 +1844,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1878,7 +1877,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'set' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1923,7 +1922,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '0:SomeDbKey:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -1963,7 +1962,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockDb->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -2029,7 +2028,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockDb->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -2089,7 +2088,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockDb->expects( $this->never() )
                        ->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -2170,7 +2169,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -2212,7 +2211,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                $mockCache->expects( $this->never() )->method( 'get' );
                $mockCache->expects( $this->never() )->method( 'delete' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );
@@ -2264,7 +2263,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                        ->method( 'delete' )
                        ->with( '0:SomeDbKey:1' );
 
-               $store = new WatchedItemStore(
+               $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
                        $mockCache
                );