2014-08-11 12:17:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class HashConfigTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers HashConfig::newInstance
|
|
|
|
|
*/
|
|
|
|
|
public function testNewInstance() {
|
|
|
|
|
$conf = HashConfig::newInstance();
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( HashConfig::class, $conf );
|
2014-08-11 12:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers HashConfig::__construct
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructor() {
|
|
|
|
|
$conf = new HashConfig();
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( HashConfig::class, $conf );
|
2014-08-11 12:17:37 +00:00
|
|
|
|
|
|
|
|
// Test passing arguments to the constructor
|
2016-02-17 09:09:32 +00:00
|
|
|
$conf2 = new HashConfig( [
|
2014-08-11 12:17:37 +00:00
|
|
|
'one' => '1',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-08-11 12:17:37 +00:00
|
|
|
$this->assertEquals( '1', $conf2->get( 'one' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers HashConfig::get
|
|
|
|
|
*/
|
|
|
|
|
public function testGet() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conf = new HashConfig( [
|
2014-08-11 12:17:37 +00:00
|
|
|
'one' => '1',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-08-11 12:17:37 +00:00
|
|
|
$this->assertEquals( '1', $conf->get( 'one' ) );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->setExpectedException( ConfigException::class, 'HashConfig::get: undefined option' );
|
2014-08-11 12:17:37 +00:00
|
|
|
$conf->get( 'two' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers HashConfig::has
|
|
|
|
|
*/
|
|
|
|
|
public function testHas() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conf = new HashConfig( [
|
2014-08-11 12:17:37 +00:00
|
|
|
'one' => '1',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-08-11 12:17:37 +00:00
|
|
|
$this->assertTrue( $conf->has( 'one' ) );
|
|
|
|
|
$this->assertFalse( $conf->has( 'two' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers HashConfig::set
|
|
|
|
|
*/
|
|
|
|
|
public function testSet() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conf = new HashConfig( [
|
2014-08-11 12:17:37 +00:00
|
|
|
'one' => '1',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-08-11 12:17:37 +00:00
|
|
|
$conf->set( 'two', '2' );
|
|
|
|
|
$this->assertEquals( '2', $conf->get( 'two' ) );
|
|
|
|
|
// Check that set overwrites
|
|
|
|
|
$conf->set( 'one', '3' );
|
|
|
|
|
$this->assertEquals( '3', $conf->get( 'one' ) );
|
|
|
|
|
}
|
2014-09-29 18:46:19 +00:00
|
|
|
}
|