Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/278592
Change subject: WatchedItemStore use PSR6 cache
......................................................................
WatchedItemStore use PSR6 cache
Change-Id: I77218b7d0e6860bb9f712ea4abcc36f2eff00953
---
M includes/WatchedItemStore.php
M tests/phpunit/includes/WatchedItemStoreUnitTest.php
2 files changed, 229 insertions(+), 243 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/92/278592/5
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 4e2dfa5..1c6053c 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -1,5 +1,6 @@
<?php
+use Psr\Cache\CacheItemPoolInterface;
use Wikimedia\Assert\Assert;
/**
@@ -18,7 +19,7 @@
private $loadBalancer;
/**
- * @var HashBagOStuff
+ * @var CacheItemPoolInterface
*/
private $cache;
@@ -47,11 +48,11 @@
/**
* @param LoadBalancer $loadBalancer
- * @param HashBagOStuff $cache
+ * @param CacheItemPoolInterface $cache
*/
public function __construct(
LoadBalancer $loadBalancer,
- HashBagOStuff $cache
+ CacheItemPoolInterface $cache
) {
$this->loadBalancer = $loadBalancer;
$this->cache = $cache;
@@ -143,17 +144,19 @@
if ( !self::$instance ) {
self::$instance = new self(
wfGetLB(),
- new HashBagOStuff( [ 'maxKeys' => 100 ] )
+ new BagOStuffPsrCache( new HashBagOStuff( [
'maxKeys' => 100 ] ) )
);
}
return self::$instance;
}
private function getCacheKey( User $user, LinkTarget $target ) {
- return $this->cache->makeKey(
- (string)$target->getNamespace(),
- $target->getDBkey(),
- (string)$user->getId()
+ return implode( '|',
+ [
+ (string)$target->getNamespace(),
+ $target->getDBkey(),
+ (string)$user->getId(),
+ ]
);
}
@@ -161,12 +164,12 @@
$user = $item->getUser();
$target = $item->getLinkTarget();
$key = $this->getCacheKey( $user, $target );
- $this->cache->set( $key, $item );
+ $this->cache->save( $this->cache->getItem( $key )->set( $item )
);
$this->cacheIndex[$target->getNamespace()][$target->getDBkey()][$user->getId()]
= $key;
}
private function uncache( User $user, LinkTarget $target ) {
- $this->cache->delete( $this->getCacheKey( $user, $target ) );
+ $this->cache->deleteItem( $this->getCacheKey( $user, $target )
);
unset(
$this->cacheIndex[$target->getNamespace()][$target->getDBkey()][$user->getId()]
);
}
@@ -175,7 +178,7 @@
return;
}
foreach (
$this->cacheIndex[$target->getNamespace()][$target->getDBkey()] as $key ) {
- $this->cache->delete( $key );
+ $this->cache->deleteItem( $key );
}
}
@@ -186,7 +189,11 @@
* @return WatchedItem|null
*/
private function getCached( User $user, LinkTarget $target ) {
- return $this->cache->get( $this->getCacheKey( $user, $target )
);
+ $item = $this->cache->getItem( $this->getCacheKey( $user,
$target ) );
+ if ( $item->isHit() ) {
+ return $item->get();
+ }
+ return null;
}
/**
diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php
b/tests/phpunit/includes/WatchedItemStoreUnitTest.php
index 869b0d2..2c6b8e6 100644
--- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php
+++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php
@@ -1,4 +1,5 @@
<?php
+use Psr\Cache\CacheItemPoolInterface;
/**
* @author Addshore
@@ -31,18 +32,64 @@
}
/**
- * @return PHPUnit_Framework_MockObject_MockObject|HashBagOStuff
+ * @return
PHPUnit_Framework_MockObject_MockObject|CacheItemPoolInterface
*/
private function getMockCache() {
- $mock = $this->getMockBuilder( HashBagOStuff::class )
+ $mock = $this->getMockBuilder( BagOStuffPsrCache::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ return $mock;
+ }
+
+ /**
+ * @param bool $isHit
+ * @param string[] $expectedMethods Method names that we want to expect
+ *
+ * @return PHPUnit_Framework_MockObject_MockObject|BagOStuffPsrCacheItem
+ */
+ private function getMockCacheItem( $isHit, array $expectedMethods = []
) {
+ $methods = [
+ 'getKey',
+ 'get',
+ 'set',
+ 'expiresAt',
+ 'expiresAfter',
+ ];
+ $mock = $this->getMockBuilder( BagOStuffPsrCacheItem::class )
->disableOriginalConstructor()
->getMock();
$mock->expects( $this->any() )
- ->method( 'makeKey' )
- ->will( $this->returnCallback( function() {
- return implode( ':', func_get_args() );
- } ) );
+ ->method( 'isHit' )
+ ->will( $this->returnValue( $isHit ) );
+ foreach ( array_diff( $methods, $expectedMethods ) as $method )
{
+ $mock->expects( $this->never() )->method( $method );
+ }
return $mock;
+ }
+
+ /**
+ * @param string[] $expectedMethods Method names that we want to expect
+ *
+ * @return
PHPUnit_Framework_MockObject_MockObject|CacheItemPoolInterface
+ */
+ private function getMockCacheWithNoExpectedCalls( array
$expectedMethods = [] ) {
+ $methods =
+ [
+ 'getItem',
+ 'getItems',
+ 'hasItem',
+ 'clear',
+ 'deleteItem',
+ 'deleteItems',
+ 'save',
+ 'saveDeferred',
+ 'commit',
+ ];
+ $mockCache = $this->getMockCache();
+ foreach ( array_diff( $methods, $expectedMethods ) as $method )
{
+ $mockCache->expects( $this->never() )->method( $method
);
+ }
+ return $mockCache;
}
/**
@@ -108,14 +155,9 @@
)
->will( $this->returnValue( 12 ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals( 12, $store->countWatchedItems( $user ) );
@@ -138,14 +180,9 @@
)
->will( $this->returnValue( 7 ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals( 7, $store->countWatchers( $titleValue ) );
@@ -189,14 +226,9 @@
$this->returnValue( $dbResult )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$expected = [
@@ -255,14 +287,9 @@
$this->returnValue( $dbResult )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$expected = [
@@ -303,14 +330,9 @@
return 'TS' . $value . 'TS';
} ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals( 7, $store->countVisitingWatchers(
$titleValue, '111' ) );
@@ -382,14 +404,9 @@
$this->returnValue( $dbResult )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$expected = [
@@ -484,14 +501,9 @@
$this->returnValue( $dbResult )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$expected = [
@@ -537,14 +549,9 @@
$this->returnValue( [] )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$expected = [
@@ -574,14 +581,9 @@
)
->will( $this->returnValue( 9 ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals( 9, $store->countUnreadNotifications( $user
) );
@@ -608,14 +610,9 @@
)
->will( $this->returnValue( 50 ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertSame(
@@ -645,14 +642,9 @@
)
->will( $this->returnValue( 9 ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals(
@@ -734,13 +726,9 @@
$this->isType( 'string' )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCache()
);
$store->duplicateEntry(
@@ -779,14 +767,9 @@
]
)
->will( $this->returnValue( new FakeResultWrapper( [] )
) );
-
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCache()
);
$store->duplicateAllAssociatedEntries(
@@ -860,13 +843,9 @@
$this->isType( 'string' )
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCache()
);
$store->duplicateAllAssociatedEntries(
@@ -893,8 +872,8 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:Some_Page:1' );
+ ->method( 'deleteItem' )
+ ->with( '0|Some_Page|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -914,7 +893,7 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )
- ->method( 'delete' );
+ ->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -951,13 +930,13 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->exactly( 2 ) )
- ->method( 'delete' );
+ ->method( 'deleteItem' );
+ $mockCache->expects( $this->at( 0 ) )
+ ->method( 'deleteItem' )
+ ->with( '0|Some_Page|1' );
$mockCache->expects( $this->at( 1 ) )
- ->method( 'delete' )
- ->with( '0:Some_Page:1' );
- $mockCache->expects( $this->at( 3 ) )
- ->method( 'delete' )
- ->with( '1:Some_Page:1' );
+ ->method( 'deleteItem' )
+ ->with( '1|Some_Page|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -994,8 +973,8 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:Some_Page:1' );
+ ->method( 'deleteItem' )
+ ->with( '0|Some_Page|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1019,7 +998,7 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )
- ->method( 'delete' );
+ ->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1044,7 +1023,7 @@
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )
- ->method( 'delete' );
+ ->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1073,12 +1052,22 @@
$this->getFakeRow( [ 'wl_notificationtimestamp'
=> '20151212010101' ] )
) );
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
+ ->method( 'set' )
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
$mockCache = $this->getMockCache();
$mockCache->expects( $this->once() )
- ->method( 'set' )
+ ->method( 'getItem' )
->with(
- '0:SomeDbKey:1'
- );
+ '0|SomeDbKey|1'
+ )
+ ->will( $this->returnValue( $mockCacheItem ) );
+ $mockCache->expects( $this->once() )
+ ->method( 'save' )
+ ->with( $mockCacheItem );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1111,8 +1100,8 @@
->will( $this->returnValue( [] ) );
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
+ $mockCache->expects( $this->never() )->method( 'getItem' );
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1133,8 +1122,8 @@
->method( 'selectRow' );
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
+ $mockCache->expects( $this->never() )->method( 'getItem' );
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1166,10 +1155,10 @@
->will( $this->returnValue( 1 ) );
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
+ $mockCache->expects( $this->never() )->method( 'getItem' );
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->method( 'deleteItem' )
+ ->with( '0|SomeDbKey|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1201,10 +1190,10 @@
->will( $this->returnValue( 0 ) );
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
+ $mockCache->expects( $this->never() )->method( 'getItem' );
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->method( 'deleteItem' )
+ ->with( '0|SomeDbKey|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1225,9 +1214,9 @@
->method( 'delete' );
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
+ $mockCache->expects( $this->never() )->method( 'getItem' );
$mockCache->expects( $this->never() )
- ->method( 'delete' );
+ ->method( 'deleteItem' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1259,19 +1248,20 @@
$this->getFakeRow( [ 'wl_notificationtimestamp'
=> '20151212010101' ] )
) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'delete' );
- $mockCache->expects( $this->once() )
- ->method( 'get' )
- ->with(
- '0:SomeDbKey:1'
- )
- ->will( $this->returnValue( null ) );
- $mockCache->expects( $this->once() )
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
->method( 'set' )
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
+ $mockCache = $this->getMockCache();
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
+ $mockCache->expects( $this->exactly( 2 ) )
+ ->method( 'getItem' )
->with(
- '0:SomeDbKey:1'
- );
+ '0|SomeDbKey|1'
+ )
+ ->will( $this->returnValue( $mockCacheItem ) );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1297,15 +1287,20 @@
$linkTarget = new TitleValue( 0, 'SomeDbKey' );
$cachedItem = new WatchedItem( $mockUser, $linkTarget,
'20151212010101' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'delete' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->once() )
+ $mockCacheItem = $this->getMockCacheItem( true, [ 'get' ] );
+ $mockCacheItem->expects( $this->once() )
->method( 'get' )
- ->with(
- '0:SomeDbKey:1'
- )
->will( $this->returnValue( $cachedItem ) );
+
+ $mockCache = $this->getMockCache();
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
+ $mockCache->expects( $this->never() )->method( 'save' );
+ $mockCache->expects( $this->once() )
+ ->method( 'getItem' )
+ ->with(
+ '0|SomeDbKey|1'
+ )
+ ->will( $this->returnValue( $mockCacheItem ) );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1336,13 +1331,15 @@
)
->will( $this->returnValue( [] ) );
+ $mockCacheItem = $this->getMockCacheItem( false );
+
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
+ $mockCache->expects( $this->never() )->method( 'save' );
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
$mockCache->expects( $this->once() )
- ->method( 'get' )
- ->with( '0:SomeDbKey:1' )
- ->will( $this->returnValue( false ) );
+ ->method( 'getItem' )
+ ->with( '0|SomeDbKey|1' )
+ ->will( $this->returnValue( $mockCacheItem ) );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1362,14 +1359,9 @@
$mockDb->expects( $this->never() )
->method( 'selectRow' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertFalse(
@@ -1397,17 +1389,21 @@
$this->getFakeRow( [ 'wl_notificationtimestamp'
=> '20151212010101' ] )
) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'delete' );
- $mockCache->expects( $this->once() )
- ->method( 'get' )
- ->with( '0:SomeDbKey:1' )
- ->will( $this->returnValue( false ) );
- $mockCache->expects( $this->once() )
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
->method( 'set' )
- ->with(
- '0:SomeDbKey:1'
- );
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
+ $mockCache = $this->getMockCache();
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
+ $mockCache->expects( $this->exactly( 2 ) )
+ ->method( 'getItem' )
+ ->with( '0|SomeDbKey|1' )
+ ->will( $this->returnValue( $mockCacheItem ) );
+ $mockCache->expects( $this->once() )
+ ->method( 'save' )
+ ->with( $mockCacheItem );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1437,13 +1433,15 @@
)
->will( $this->returnValue( [] ) );
+ $mockCacheItem = $this->getMockCacheItem( false );
+
$mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
+ $mockCache->expects( $this->never() )->method( 'save' );
+ $mockCache->expects( $this->never() )->method( 'deleteItem' );
$mockCache->expects( $this->once() )
- ->method( 'get' )
- ->with( '0:SomeDbKey:1' )
- ->will( $this->returnValue( false ) );
+ ->method( 'getItem' )
+ ->with( '0|SomeDbKey|1' )
+ ->will( $this->returnValue( $mockCacheItem ) );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1463,14 +1461,9 @@
$mockDb->expects( $this->never() )
->method( 'selectRow' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertFalse(
@@ -1486,14 +1479,9 @@
$mockDb->expects( $this->never() )
->method( 'selectRow' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertFalse(
@@ -1519,14 +1507,9 @@
)
->will( $this->returnValue( [] ) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertFalse(
@@ -1557,17 +1540,22 @@
$this->getFakeRow( [ 'wl_notificationtimestamp'
=> '20151212010101' ] )
) );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->once() )
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
->method( 'set' )
- ->with(
- '0:SomeDbKey:1',
- $this->isInstanceOf( WatchedItem::class )
- );
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
+ $mockCache = $this->getMockCache();
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->method( 'getItem' )
+ ->will( $this->returnValue( $mockCacheItem ) );
+ $mockCache->expects( $this->once() )
+ ->method( 'save' )
+ ->with( $mockCacheItem );
+ $mockCache->expects( $this->once() )
+ ->method( 'deleteItem' )
+ ->with( '0|SomeDbKey|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1601,17 +1589,9 @@
$mockDb->expects( $this->never() )
->method( 'selectRow' );
- $mockCache = $this->getMockCache();
- $mockDb->expects( $this->never() )
- ->method( 'get' );
- $mockDb->expects( $this->never() )
- ->method( 'set' );
- $mockDb->expects( $this->never() )
- ->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls( [ 'deleteItem'
] )
);
// Note: This does not actually assert the job is correct
@@ -1667,17 +1647,9 @@
$mockDb->expects( $this->never() )
->method( 'selectRow' );
- $mockCache = $this->getMockCache();
- $mockDb->expects( $this->never() )
- ->method( 'get' );
- $mockDb->expects( $this->never() )
- ->method( 'set' );
- $mockDb->expects( $this->never() )
- ->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls( [ 'deleteItem'
] )
);
// Note: This does not actually assert the job is correct
@@ -1727,13 +1699,23 @@
$this->getFakeRow( [ 'wl_notificationtimestamp'
=> '20151212010101' ] )
) );
- $mockCache = $this->getMockCache();
- $mockDb->expects( $this->never() )
- ->method( 'get' );
- $mockDb->expects( $this->never() )
- ->method( 'set' );
- $mockDb->expects( $this->never() )
- ->method( 'delete' );
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
+ ->method( 'set' )
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
+ $mockCache = $this->getMockCacheWithNoExpectedCalls( [
'getItem', 'save', 'deleteItem' ] );
+ $mockCache->expects( $this->once() )
+ ->method( 'getItem' )
+ ->with( '0|SomeDbKey|1' )
+ ->will( $this->returnValue( $mockCacheItem ) );
+ $mockCache->expects( $this->once() )
+ ->method( 'save' )
+ ->with( $mockCacheItem );
+ $mockCache->expects( $this->once() )
+ ->method( 'deleteItem' )
+ ->with( '0|SomeDbKey|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
@@ -1811,14 +1793,9 @@
]
);
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$this->assertEquals(
@@ -1853,14 +1830,9 @@
$mockDb->expects( $this->never() )
->method( 'update' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->never() )->method( 'set' );
- $mockCache->expects( $this->never() )->method( 'get' );
- $mockCache->expects( $this->never() )->method( 'delete' );
-
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $this->getMockCacheWithNoExpectedCalls()
);
$watchers = $store->updateNotificationTimestamp(
@@ -1899,16 +1871,23 @@
$mockDb->expects( $this->once() )
->method( 'update' );
- $mockCache = $this->getMockCache();
- $mockCache->expects( $this->once() )
+ $mockCacheItem = $this->getMockCacheItem( false, [ 'set' ] );
+ $mockCacheItem->expects( $this->once() )
->method( 'set' )
- ->with( '0:SomeDbKey:1', $this->isType( 'object' ) );
+ ->with( $this->isInstanceOf( WatchedItem::class ) )
+ ->will( $this->returnValue( $mockCacheItem ) );
+
+ $mockCache = $this->getMockCache();
+ $mockCache->expects( $this->exactly( 2 ) )
+ ->method( 'getItem' )
+ ->with( '0|SomeDbKey|1' )
+ ->will( $this->returnValue( $mockCacheItem ) );
$mockCache->expects( $this->once() )
- ->method( 'get' )
- ->with( '0:SomeDbKey:1' );
+ ->method( 'save' )
+ ->with( $mockCacheItem );
$mockCache->expects( $this->once() )
- ->method( 'delete' )
- ->with( '0:SomeDbKey:1' );
+ ->method( 'deleteItem' )
+ ->with( '0|SomeDbKey|1' );
$store = new WatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
--
To view, visit https://gerrit.wikimedia.org/r/278592
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77218b7d0e6860bb9f712ea4abcc36f2eff00953
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits