Test coverage WatchedItemStore::addWatchBatchForUser to 100%
authoraddshore <addshorewiki@gmail.com>
Mon, 18 Apr 2016 11:25:54 +0000 (12:25 +0100)
committeraddshore <addshorewiki@gmail.com>
Mon, 18 Apr 2016 11:42:24 +0000 (12:42 +0100)
Change-Id: I6ff916519af87a40187d86149b0b72c2ab5a5f26

tests/phpunit/includes/WatchedItemStoreUnitTest.php

index 414f3b6..9b3e798 100644 (file)
@@ -17,7 +17,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 +37,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                }
                $mock->expects( $this->any() )
                        ->method( 'getReadOnlyReason' )
-                       ->will( $this->returnValue( false ) );
+                       ->will( $this->returnValue( $readOnlyReason ) );
                return $mock;
        }
 
@@ -941,6 +945,20 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
                );
        }
 
+       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() )