X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2Fobjectcache%2FBagOStuffTest.php;h=92fb95418cdc7f9390da81f281f7d8973e2779f7;hb=d7c4e65fddc7a737395cb1dbaedb4d51eff3cc43;hp=96e200dc9d641618e42ada0848301d1475f81d85;hpb=40a628a501fc05bb00e834fe359ca4061925f320;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php index 96e200dc9d..92fb95418c 100644 --- a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php @@ -138,6 +138,20 @@ class BagOStuffTest extends MediaWikiTestCase { } } + /** + * @covers BagOStuff::changeTTL + */ + public function testChangeTTL() { + $key = wfMemcKey( 'test' ); + $value = 'meow'; + + $this->cache->add( $key, $value ); + $this->assertTrue( $this->cache->changeTTL( $key, 5 ) ); + $this->assertEquals( $this->cache->get( $key ), $value ); + $this->cache->delete( $key ); + $this->assertFalse( $this->cache->changeTTL( $key, 5 ) ); + } + /** * @covers BagOStuff::add */ @@ -252,4 +266,29 @@ class BagOStuffTest extends MediaWikiTestCase { $this->assertType( 'ScopedCallback', $value1, 'First reentrant call returned lock' ); $this->assertType( 'ScopedCallback', $value1, 'Second reentrant call returned lock' ); } + + /** + * @covers BagOStuff::__construct + * @covers BagOStuff::trackDuplicateKeys + */ + public function testReportDupes() { + $logger = $this->getMock( 'Psr\Log\NullLogger' ); + $logger->expects( $this->once() ) + ->method( 'warning' ) + ->with( 'Duplicate get(): "{key}" fetched {count} times', [ + 'key' => 'foo', + 'count' => 2, + ] ); + + $cache = new HashBagOStuff( [ + 'reportDupes' => true, + 'asyncHandler' => 'DeferredUpdates::addCallableUpdate', + 'logger' => $logger, + ] ); + $cache->get( 'foo' ); + $cache->get( 'bar' ); + $cache->get( 'foo' ); + + DeferredUpdates::doUpdates(); + } }