Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / tests / phpunit / includes / watcheditem / WatchedItemStoreUnitTest.php
index 52e653c..8ef8cb0 100644 (file)
@@ -47,6 +47,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
        private function getMockCache() {
                $mock = $this->getMockBuilder( HashBagOStuff::class )
                        ->disableOriginalConstructor()
+                       ->setMethods( [ 'get', 'set', 'delete', 'makeKey' ] )
                        ->getMock();
                $mock->expects( $this->any() )
                        ->method( 'makeKey' )
@@ -443,7 +444,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        )
                        ->will( $this->returnCallback( function ( $a, $conj ) {
                                $sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
-                               return join( $sqlConj, array_map( function ( $s ) {
+                               return implode( $sqlConj, array_map( function ( $s ) {
                                        return '(' . $s . ')';
                                }, $a
                                ) );
@@ -460,7 +461,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        "(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() )
@@ -540,7 +541,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        )
                        ->will( $this->returnCallback( function ( $a, $conj ) {
                                $sqlConj = $conj === LIST_AND ? ' AND ' : ' OR ';
-                               return join( $sqlConj, array_map( function ( $s ) {
+                               return implode( $sqlConj, array_map( function ( $s ) {
                                        return '(' . $s . ')';
                                }, $a
                                ) );
@@ -563,7 +564,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        "(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 ' .
@@ -2074,12 +2075,11 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ->method( 'selectRow' );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->never() )->method( 'set' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeDbKey:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
@@ -2168,12 +2168,11 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ->method( 'selectRow' );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->never() )->method( 'set' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeTitle:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
@@ -2235,12 +2234,13 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ) );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'set' )
+                       ->with( '0:SomeDbKey:1', $this->isType( 'object' ) );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeDbKey:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
@@ -2311,12 +2311,11 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ->will( $this->returnValue( false ) );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->never() )->method( 'set' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeDbKey:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
@@ -2378,12 +2377,13 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ) );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'set' )
+                       ->with( '0:SomeDbKey:1', $this->isType( 'object' ) );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeDbKey:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),
@@ -2456,12 +2456,13 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                        ) );
 
                $mockCache = $this->getMockCache();
-               $mockDb->expects( $this->never() )
-                       ->method( 'get' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'set' );
-               $mockDb->expects( $this->never() )
-                       ->method( 'delete' );
+               $mockCache->expects( $this->never() )->method( 'get' );
+               $mockCache->expects( $this->once() )
+                       ->method( 'set' )
+                       ->with( '0:SomeDbKey:1', $this->isType( 'object' ) );
+               $mockCache->expects( $this->once() )
+                       ->method( 'delete' )
+                       ->with( '0:SomeDbKey:1' );
 
                $store = $this->newWatchedItemStore(
                        $this->getMockLoadBalancer( $mockDb ),