Merge "Tell users that js/css subpages are public"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / objectcache / CachedBagOStuffTest.php
index 3b19c9a..a01cc6b 100644 (file)
@@ -5,6 +5,10 @@
  */
 class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
 
+       /**
+        * @covers CachedBagOStuff::__construct
+        * @covers CachedBagOStuff::doGet
+        */
        public function testGetFromBackend() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -16,6 +20,10 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 'bar', $cache->get( 'foo' ), 'cached' );
        }
 
+       /**
+        * @covers CachedBagOStuff::set
+        * @covers CachedBagOStuff::delete
+        */
        public function testSetAndDelete() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -30,6 +38,10 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                }
        }
 
+       /**
+        * @covers CachedBagOStuff::set
+        * @covers CachedBagOStuff::delete
+        */
        public function testWriteCacheOnly() {
                $backend = new HashBagOStuff;
                $cache = new CachedBagOStuff( $backend );
@@ -49,4 +61,25 @@ class CachedBagOStuffTest extends PHPUnit_Framework_TestCase {
                $cache->delete( 'foo', CachedBagOStuff::WRITE_CACHE_ONLY );
                $this->assertEquals( 'old', $cache->get( 'foo' ) ); // Reloaded from backend
        }
+
+       /**
+        * @covers CachedBagOStuff::doGet
+        */
+       public function testCacheBackendMisses() {
+               $backend = new HashBagOStuff;
+               $cache = new CachedBagOStuff( $backend );
+
+               // First hit primes the cache with miss from the backend
+               $this->assertEquals( false, $cache->get( 'foo' ) );
+
+               // Change the value in the backend
+               $backend->set( 'foo', true );
+
+               // Second hit returns the cached miss
+               $this->assertEquals( false, $cache->get( 'foo' ) );
+
+               // But a fresh value is read from the backend
+               $backend->set( 'bar', true );
+               $this->assertEquals( true, $cache->get( 'bar' ) );
+       }
 }