Debian Codegraph @

tests/phpunit/unit/includes/Settings/Config/ConfigBuilderBaseTest.php

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