objectcache: Add a clear() method to HashBagOStuff
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 3 Nov 2015 06:49:13 +0000 (06:49 +0000)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 3 Nov 2015 10:07:10 +0000 (10:07 +0000)
Including tests for delete() and clear().

Change-Id: If39d729838e312523f0df3ae8b235ebe939a17fd

includes/libs/objectcache/HashBagOStuff.php
tests/phpunit/includes/libs/objectcache/HashBagOStuffTest.php

index a058ecf..6a43403 100644 (file)
@@ -94,4 +94,8 @@ class HashBagOStuff extends BagOStuff {
 
                return true;
        }
+
+       public function clear() {
+               $this->bag = array();
+       }
 }
index 4f8a3cb..39b84e1 100644 (file)
@@ -5,6 +5,28 @@
  */
 class HashBagOStuffTest extends PHPUnit_Framework_TestCase {
 
+       public function testDelete() {
+               $cache = new HashBagOStuff();
+               for ( $i = 0; $i < 10; $i++ ) {
+                       $cache->set( "key$i", 1 );
+                       $this->assertEquals( 1, $cache->get( "key$i" ) );
+                       $cache->delete( "key$i" );
+                       $this->assertEquals( false, $cache->get( "key$i" ) );
+               }
+       }
+
+       public function testClear() {
+               $cache = new HashBagOStuff();
+               for ( $i = 0; $i < 10; $i++ ) {
+                       $cache->set( "key$i", 1 );
+                       $this->assertEquals( 1, $cache->get( "key$i" ) );
+               }
+               $cache->clear();
+               for ( $i = 0; $i < 10; $i++ ) {
+                       $this->assertEquals( false, $cache->get( "key$i" ) );
+               }
+       }
+
        public function testEvictionOrder() {
                $cache = new HashBagOStuff( array( 'maxKeys' => 10 ) );
                for ( $i = 0; $i < 10; $i++ ) {