X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2Fobjectcache%2FBagOStuffTest.php;h=da532b080c0a0259f99d683f565dc6b627a34ffa;hb=d8b952ae47;hp=1d11fd8ef2d87bce7228ebb8671c7741e9eb82b3;hpb=699920cc66790c3f5675ffa340c361950ee6225f;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php index 1d11fd8ef2..da532b080c 100644 --- a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php @@ -129,6 +129,59 @@ class BagOStuffTest extends MediaWikiTestCase { $this->assertFalse( $this->cache->get( $key ) ); } + /** + * @covers BagOStuff::changeTTLMulti + */ + public function testChangeTTLMulti() { + $key1 = $this->cache->makeKey( 'test-key1' ); + $key2 = $this->cache->makeKey( 'test-key2' ); + $key3 = $this->cache->makeKey( 'test-key3' ); + $key4 = $this->cache->makeKey( 'test-key4' ); + + // cleanup + $this->cache->delete( $key1 ); + $this->cache->delete( $key2 ); + $this->cache->delete( $key3 ); + $this->cache->delete( $key4 ); + + $ok = $this->cache->changeTTLMulti( [ $key1, $key2, $key3 ], 30 ); + $this->assertFalse( $ok, "No keys found" ); + $this->assertFalse( $this->cache->get( $key1 ) ); + $this->assertFalse( $this->cache->get( $key2 ) ); + $this->assertFalse( $this->cache->get( $key3 ) ); + + $ok = $this->cache->setMulti( [ $key1 => 1, $key2 => 2, $key3 => 3 ] ); + + $this->assertTrue( $ok, "setMulti() succeeded" ); + $this->assertEquals( + 3, + count( $this->cache->getMulti( [ $key1, $key2, $key3 ] ) ), + "setMulti() succeeded via getMulti() check" + ); + + $ok = $this->cache->changeTTLMulti( [ $key1, $key2, $key3 ], 300 ); + $this->assertTrue( $ok, "TTL bumped for all keys" ); + $this->assertEquals( 1, $this->cache->get( $key1 ) ); + $this->assertEquals( 2, $this->cache->get( $key2 ) ); + $this->assertEquals( 3, $this->cache->get( $key3 ) ); + + $ok = $this->cache->changeTTLMulti( [ $key1, $key2, $key3 ], time() + 86400 ); + $this->assertTrue( $ok, "Expiry set for all keys" ); + + $ok = $this->cache->changeTTLMulti( [ $key1, $key2, $key3, $key4 ], 300 ); + $this->assertFalse( $ok, "One key missing" ); + + $this->assertEquals( 2, $this->cache->incr( $key1 ) ); + $this->assertEquals( 3, $this->cache->incr( $key2 ) ); + $this->assertEquals( 4, $this->cache->incr( $key3 ) ); + + // cleanup + $this->cache->delete( $key1 ); + $this->cache->delete( $key2 ); + $this->cache->delete( $key3 ); + $this->cache->delete( $key4 ); + } + /** * @covers BagOStuff::add */ @@ -304,6 +357,7 @@ class BagOStuffTest extends MediaWikiTestCase { $this->cache->set( $key, 666, 10, BagOStuff::WRITE_ALLOW_SEGMENTS ); + $this->assertEquals( 666, $this->cache->get( $key ) ); $this->assertEquals( 667, $this->cache->incr( $key ) ); $this->assertEquals( 667, $this->cache->get( $key ) );