Merge "rdbms: avoid LoadBalancer::getConnection waste when using $groups"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / MapCacheLRUTest.php
index 79f7b96..7147c6f 100644 (file)
@@ -158,10 +158,12 @@ class MapCacheLRUTest extends PHPUnit\Framework\TestCase {
                $now += 29;
                $this->assertTrue( $cache->has( 'd', 30 ) );
                $this->assertEquals( 'xxx', $cache->get( 'd' ) );
+               $this->assertEquals( 'xxx', $cache->get( 'd', 30 ) );
 
                $now += 1.5;
                $this->assertFalse( $cache->has( 'd', 30 ) );
                $this->assertEquals( 'xxx', $cache->get( 'd' ) );
+               $this->assertNull( $cache->get( 'd', 30 ) );
        }
 
        /**
@@ -180,14 +182,17 @@ class MapCacheLRUTest extends PHPUnit\Framework\TestCase {
                $cache->setField( 'PMs', 'Margaret Thatcher', 'Tory' );
                $this->assertTrue( $cache->hasField( 'PMs', 'Tony Blair', 30 ) );
                $this->assertEquals( 'Labour', $cache->getField( 'PMs', 'Tony Blair' ) );
+               $this->assertTrue( $cache->hasField( 'PMs', 'Tony Blair', 30 ) );
 
                $now += 29;
                $this->assertTrue( $cache->hasField( 'PMs', 'Tony Blair', 30 ) );
                $this->assertEquals( 'Labour', $cache->getField( 'PMs', 'Tony Blair' ) );
+               $this->assertEquals( 'Labour', $cache->getField( 'PMs', 'Tony Blair', 30 ) );
 
                $now += 1.5;
                $this->assertFalse( $cache->hasField( 'PMs', 'Tony Blair', 30 ) );
                $this->assertEquals( 'Labour', $cache->getField( 'PMs', 'Tony Blair' ) );
+               $this->assertNull( $cache->getField( 'PMs', 'Tony Blair', 30 ) );
 
                $this->assertEquals(
                        [ 'Tony Blair' => 'Labour', 'Margaret Thatcher' => 'Tory' ],
@@ -209,4 +214,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() );
+               }
+       }
 }