<?php
+use Wikimedia\TestingAccessWrapper;
+
/**
* @group BagOStuff
*/
class HashBagOStuffTest extends PHPUnit_Framework_TestCase {
+ use MediaWikiCoversValidator;
+
+ /**
+ * @covers HashBagOStuff::__construct
+ */
+ public function testConstruct() {
+ $this->assertInstanceOf(
+ HashBagOStuff::class,
+ new HashBagOStuff()
+ );
+ }
+
+ /**
+ * @covers HashBagOStuff::__construct
+ * @expectedException InvalidArgumentException
+ */
+ public function testConstructBadZero() {
+ $cache = new HashBagOStuff( [ 'maxKeys' => 0 ] );
+ }
+
+ /**
+ * @covers HashBagOStuff::__construct
+ * @expectedException InvalidArgumentException
+ */
+ public function testConstructBadNeg() {
+ $cache = new HashBagOStuff( [ 'maxKeys' => -1 ] );
+ }
+
+ /**
+ * @covers HashBagOStuff::__construct
+ * @expectedException InvalidArgumentException
+ */
+ public function testConstructBadType() {
+ $cache = new HashBagOStuff( [ 'maxKeys' => 'x' ] );
+ }
+
/**
* @covers HashBagOStuff::delete
*/
/**
* Ensure maxKeys eviction prefers keeping new keys.
*
- * @covers HashBagOStuff::__construct
* @covers HashBagOStuff::set
*/
public function testEvictionAdd() {
for ( $i = 10; $i < 20; $i++ ) {
$cache->set( "key$i", 1 );
$this->assertEquals( 1, $cache->get( "key$i" ) );
- $this->assertEquals( false, $cache->get( "key" . $i - 10 ) );
+ $this->assertEquals( false, $cache->get( "key" . ( $i - 10 ) ) );
}
}
* Ensure maxKeys eviction prefers recently set keys
* even if the keys pre-exist.
*
- * @covers HashBagOStuff::__construct
* @covers HashBagOStuff::set
*/
public function testEvictionSet() {
/**
* Ensure maxKeys eviction prefers recently retrieved keys (LRU).
*
- * @covers HashBagOStuff::__construct
* @covers HashBagOStuff::doGet
* @covers HashBagOStuff::hasKey
*/