Merge "Fix exception when viewing special pages with relative related titles"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / MapCacheLRUTest.php
index a06ef62..0c8dc68 100644 (file)
@@ -69,6 +69,21 @@ class MapCacheLRUTest extends PHPUnit\Framework\TestCase {
                );
        }
 
+       /**
+        * @covers MapCacheLRU::has()
+        * @covers MapCacheLRU::get()
+        * @covers MapCacheLRU::set()
+        */
+       function testMissing() {
+               $raw = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
+               $cache = MapCacheLRU::newFromArray( $raw, 3 );
+
+               $this->assertFalse( $cache->has( 'd' ) );
+               $this->assertNull( $cache->get( 'd' ) );
+               $this->assertNull( $cache->get( 'd', 0.0, null ) );
+               $this->assertFalse( $cache->get( 'd', 0.0, false ) );
+       }
+
        /**
         * @covers MapCacheLRU::has()
         * @covers MapCacheLRU::get()
@@ -214,4 +229,54 @@ class MapCacheLRUTest extends PHPUnit\Framework\TestCase {
                $this->assertEquals( 1983, $cache->getField( 'MPs', 'Edwina Currie' ) );
                $this->assertEquals( 1970, $cache->getField( 'MPs', 'Neil Kinnock' ) );
        }
+
+       /**
+        * @covers MapCacheLRU::has()
+        * @covers MapCacheLRU::get()
+        * @covers MapCacheLRU::set()
+        * @covers MapCacheLRU::hasField()
+        * @covers MapCacheLRU::getField()
+        * @covers MapCacheLRU::setField()
+        */
+       public function testInvalidKeys() {
+               $cache = MapCacheLRU::newFromArray( [], 3 );
+
+               try {
+                       $cache->has( 3.4 );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+               try {
+                       $cache->get( false );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+               try {
+                       $cache->set( 3.4, 'x' );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+
+               try {
+                       $cache->hasField( 'x', 3.4 );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+               try {
+                       $cache->getField( 'x', false );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+               try {
+                       $cache->setField( 'x', 3.4, 'x' );
+                       $this->fail( "No exception" );
+               } catch ( UnexpectedValueException $e ) {
+                       $this->assertRegExp( '/must be string or integer/', $e->getMessage() );
+               }
+       }
 }