| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Config\ConfigException; |
| 4 |
use MediaWiki\Config\HashConfig; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class HashConfigTest extends \MediaWikiUnitTestCase { |
| 10 |
|
| 11 |
public function testNewInstance() { |
| 12 |
$conf = HashConfig::newInstance(); |
| 13 |
$this->assertInstanceOf( HashConfig::class, $conf ); |
| 14 |
} |
| 15 |
|
| 16 |
public function testConstructor() { |
| 17 |
$conf = new HashConfig(); |
| 18 |
$this->assertInstanceOf( HashConfig::class, $conf ); |
| 19 |
|
| 20 |
|
| 21 |
$conf2 = new HashConfig( [ |
| 22 |
'one' => '1', |
| 23 |
] ); |
| 24 |
$this->assertSame( '1', $conf2->get( 'one' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
public function testGet() { |
| 28 |
$conf = new HashConfig( [ |
| 29 |
'one' => '1', |
| 30 |
] ); |
| 31 |
$this->assertSame( '1', $conf->get( 'one' ) ); |
| 32 |
$this->expectException( ConfigException::class ); |
| 33 |
$this->expectExceptionMessage( 'HashConfig::get: undefined option' ); |
| 34 |
$conf->get( 'two' ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testHas() { |
| 38 |
$conf = new HashConfig( [ |
| 39 |
'one' => '1', |
| 40 |
] ); |
| 41 |
$this->assertTrue( $conf->has( 'one' ) ); |
| 42 |
$this->assertFalse( $conf->has( 'two' ) ); |
| 43 |
} |
| 44 |
|
| 45 |
public function testClear() { |
| 46 |
$conf = new HashConfig( [ |
| 47 |
'one' => '1', |
| 48 |
] ); |
| 49 |
$this->assertTrue( $conf->has( 'one' ) ); |
| 50 |
|
| 51 |
$conf->clear(); |
| 52 |
$this->assertFalse( $conf->has( 'one' ) ); |
| 53 |
} |
| 54 |
|
| 55 |
public function testSet() { |
| 56 |
$conf = new HashConfig( [ |
| 57 |
'one' => '1', |
| 58 |
] ); |
| 59 |
$conf->set( 'two', '2' ); |
| 60 |
$this->assertSame( '2', $conf->get( 'two' ) ); |
| 61 |
|
| 62 |
$conf->set( 'one', '3' ); |
| 63 |
$this->assertSame( '3', $conf->get( 'one' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
public function testGetNames() { |
| 67 |
$conf = new HashConfig( [ |
| 68 |
'one' => '1', |
| 69 |
] ); |
| 70 |
$conf->set( 'two', '2' ); |
| 71 |
|
| 72 |
$this->assertSame( [ 'one', 'two' ], $conf->getNames() ); |
| 73 |
} |
| 74 |
|
| 75 |
public function testTraversable() { |
| 76 |
$conf = new HashConfig( [ |
| 77 |
'one' => '1', |
| 78 |
] ); |
| 79 |
$conf->set( 'two', '2' ); |
| 80 |
|
| 81 |
$actual = []; |
| 82 |
foreach ( $conf as $name => $value ) { |
| 83 |
$actual[$name] = $value; |
| 84 |
} |
| 85 |
|
| 86 |
$this->assertSame( [ 'one' => '1', 'two' => '2' ], $actual ); |
| 87 |
} |
| 88 |
} |