Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat"
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreUnitTest.php
index ba47059..b71e8f4 100644 (file)
@@ -13,7 +13,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
         * @return PHPUnit_Framework_MockObject_MockObject|IDatabase
         */
        private function getMockDb() {
-               return $this->getMock( IDatabase::class );
+               return $this->createMock( IDatabase::class );
        }
 
        /**
@@ -63,7 +63,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
         * @return PHPUnit_Framework_MockObject_MockObject|User
         */
        private function getMockNonAnonUserWithId( $id ) {
-               $mock = $this->getMock( User::class );
+               $mock = $this->createMock( User::class );
                $mock->expects( $this->any() )
                        ->method( 'isAnon' )
                        ->will( $this->returnValue( false ) );
@@ -1978,7 +1978,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
         * @return PHPUnit_Framework_MockObject_MockObject|Title
         */
        private function getMockTitle( $text, $ns = 0 ) {
-               $title = $this->getMock( Title::class );
+               $title = $this->createMock( Title::class );
                $title->expects( $this->any() )
                        ->method( 'getText' )
                        ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
@@ -2404,6 +2404,35 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                );
        }
 
+       public function testSetNotificationTimestampsForUser_nullTimestamp() {
+               $user = $this->getMockNonAnonUserWithId( 1 );
+               $timestamp = null;
+
+               $mockDb = $this->getMockDb();
+               $mockDb->expects( $this->once() )
+                       ->method( 'update' )
+                       ->with(
+                               'watchlist',
+                               [ 'wl_notificationtimestamp' => null ],
+                               [ 'wl_user' => 1 ]
+                       )
+                       ->will( $this->returnValue( true ) );
+               $mockDb->expects( $this->exactly( 0 ) )
+                       ->method( 'timestamp' )
+                       ->will( $this->returnCallback( function( $value ) {
+                               return 'TS' . $value . 'TS';
+                       } ) );
+
+               $store = $this->newWatchedItemStore(
+                       $this->getMockLoadBalancer( $mockDb ),
+                       $this->getMockCache()
+               );
+
+               $this->assertTrue(
+                       $store->setNotificationTimestampsForUser( $user, $timestamp )
+               );
+       }
+
        public function testSetNotificationTimestampsForUser_specificTargets() {
                $user = $this->getMockNonAnonUserWithId( 1 );
                $timestamp = '20100101010101';