1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
<?php
namespace MediaWiki\Tests\Unit\Settings\Config;
use MediaWiki\Config\Config;
use MediaWiki\Config\HashConfig;
use MediaWiki\Settings\Config\ConfigBuilder;
use MediaWiki\Settings\Config\ConfigBuilderBase;
use MediaWiki\Settings\Config\GlobalConfigBuilder;
use PHPUnit\Framework\TestCase;
/**
* @covers \MediaWiki\Settings\Config\ConfigBuilderBase
*/
class ConfigBuilderBaseTest extends TestCase {
use ConfigSinkTestTrait;
/** @var ConfigBuilder */
private $builder;
/**
* @before
*/
protected function configBuilderSetUp() {
// Similar to ArrayConfigBuilder, but without optimizations,
// so we can use the generic implementations.
$this->builder = new class() extends ConfigBuilderBase {
private $config = [];
public function build(): Config {
return new HashConfig( $this->config );
}
protected function has( string $key ): bool {
return array_key_exists( $key, $this->config );
}
public function get( string $key ) {
return $this->config[$key];
}
protected function update( string $key, $value ) {
$this->config[$key] = $value;
}
};
}
protected function getConfigSink(): ConfigBuilder {
return $this->builder;
}
protected function assertKeyHasValue( string $key, $value ) {
$this->assertSame( $value, $this->builder->get( $key ) );
}
public function testBuild() {
$builder = new GlobalConfigBuilder();
$builder
->set( 'foo', 'bar' )
->set( 'baz', 'quu' );
$this->assertSame( 'bar', $builder->build()->get( 'foo' ) );
$this->assertSame( 'quu', $builder->build()->get( 'baz' ) );
}
}
|