Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-09-20 07:54:42 +00:00
|
|
|
use MediaWiki\Config\Config;
|
|
|
|
|
use MediaWiki\Config\ConfigException;
|
|
|
|
|
use MediaWiki\Config\ConfigFactory;
|
|
|
|
|
use MediaWiki\Config\GlobalVarConfig;
|
|
|
|
|
use MediaWiki\Config\HashConfig;
|
|
|
|
|
|
config: Widen `@covers` annotations in unit tests
Follows-up I7555c9b6b510, I6d845bdfbb80, I69b5385868, I4c7d826c7e,
I1287f3979ab, which widened the `@covers` annotations of other suites:
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I've audited each test to confirm it is a general test of the
> subject class, where adding any called methods would be an accepted
> change, thus widening it is merely a no-op that clarifies intent
> and reduces maintenance. I am not disabling the "only track coverage
> of specified subject" benefits, nor am I claiming coverage in
> in classes outside the subject under test.
>
> Tracking tiny details per-method wastes time in keeping references
> in sync during refactors, time to realize (and fix) when people
> inevitably don't keep them in sync, time lost in finding uncovered
> code to write tests for only to realize it was already covered but
> not yet claimed, etc.
Change-Id: Ie3d6a2b4e79b6aa0dc1d2414a3ae7e2bad209c7b
2023-07-23 21:47:08 +00:00
|
|
|
/**
|
2024-01-27 00:11:07 +00:00
|
|
|
* @covers \MediaWiki\Config\ConfigFactory
|
config: Widen `@covers` annotations in unit tests
Follows-up I7555c9b6b510, I6d845bdfbb80, I69b5385868, I4c7d826c7e,
I1287f3979ab, which widened the `@covers` annotations of other suites:
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I've audited each test to confirm it is a general test of the
> subject class, where adding any called methods would be an accepted
> change, thus widening it is merely a no-op that clarifies intent
> and reduces maintenance. I am not disabling the "only track coverage
> of specified subject" benefits, nor am I claiming coverage in
> in classes outside the subject under test.
>
> Tracking tiny details per-method wastes time in keeping references
> in sync during refactors, time to realize (and fix) when people
> inevitably don't keep them in sync, time lost in finding uncovered
> code to write tests for only to realize it was already covered but
> not yet claimed, etc.
Change-Id: Ie3d6a2b4e79b6aa0dc1d2414a3ae7e2bad209c7b
2023-07-23 21:47:08 +00:00
|
|
|
*/
|
2019-07-08 13:25:31 +00:00
|
|
|
class ConfigFactoryTest extends \MediaWikiIntegrationTestCase {
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
|
|
|
|
|
public function testRegister() {
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
|
2016-05-01 19:29:11 +00:00
|
|
|
$this->assertInstanceOf( GlobalVarConfig::class, $factory->makeConfig( 'unittest' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRegisterInvalid() {
|
|
|
|
|
$factory = new ConfigFactory();
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
$factory->register( 'invalid', 'Invalid callback' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 09:44:46 +00:00
|
|
|
public function testRegisterInvalidInstance() {
|
|
|
|
|
$factory = new ConfigFactory();
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2020-02-28 15:13:53 +00:00
|
|
|
$factory->register( 'invalidInstance', (object)[] );
|
2018-01-20 09:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-01 19:29:11 +00:00
|
|
|
public function testRegisterInstance() {
|
|
|
|
|
$config = GlobalVarConfig::newInstance();
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( 'unittest', $config );
|
|
|
|
|
$this->assertSame( $config, $factory->makeConfig( 'unittest' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRegisterAgain() {
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
$config1 = $factory->makeConfig( 'unittest' );
|
|
|
|
|
|
|
|
|
|
$factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
$config2 = $factory->makeConfig( 'unittest' );
|
|
|
|
|
|
|
|
|
|
$this->assertNotSame( $config1, $config2 );
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 19:02:31 +00:00
|
|
|
public function testSalvage() {
|
|
|
|
|
$oldFactory = new ConfigFactory();
|
|
|
|
|
$oldFactory->register( 'foo', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
$oldFactory->register( 'bar', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
$oldFactory->register( 'quux', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
|
|
|
|
|
// instantiate two of the three defined configurations
|
|
|
|
|
$foo = $oldFactory->makeConfig( 'foo' );
|
|
|
|
|
$bar = $oldFactory->makeConfig( 'bar' );
|
|
|
|
|
$quux = $oldFactory->makeConfig( 'quux' );
|
|
|
|
|
|
|
|
|
|
// define new config instance
|
|
|
|
|
$newFactory = new ConfigFactory();
|
|
|
|
|
$newFactory->register( 'foo', 'GlobalVarConfig::newInstance' );
|
2021-02-07 13:10:36 +00:00
|
|
|
$newFactory->register( 'bar', static function () {
|
2016-04-14 19:02:31 +00:00
|
|
|
return new HashConfig();
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
// "foo" and "quux" are defined in the old and the new factory.
|
|
|
|
|
// The old factory has instances for "foo" and "bar", but not "quux".
|
|
|
|
|
$newFactory->salvage( $oldFactory );
|
|
|
|
|
|
|
|
|
|
$newFoo = $newFactory->makeConfig( 'foo' );
|
|
|
|
|
$this->assertSame( $foo, $newFoo, 'existing instance should be salvaged' );
|
|
|
|
|
|
|
|
|
|
$newBar = $newFactory->makeConfig( 'bar' );
|
|
|
|
|
$this->assertNotSame( $bar, $newBar, 'don\'t salvage if callbacks differ' );
|
|
|
|
|
|
|
|
|
|
// the new factory doesn't have quux defined, so the quux instance should not be salvaged
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( ConfigException::class );
|
2016-04-14 19:02:31 +00:00
|
|
|
$newFactory->makeConfig( 'quux' );
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-01 19:29:11 +00:00
|
|
|
public function testGetConfigNames() {
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( 'foo', 'GlobalVarConfig::newInstance' );
|
|
|
|
|
$factory->register( 'bar', new HashConfig() );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( [ 'foo', 'bar' ], $factory->getConfigNames() );
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 00:33:16 +00:00
|
|
|
public function testMakeConfigWithCallback() {
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
|
2016-05-01 19:29:11 +00:00
|
|
|
|
|
|
|
|
$conf = $factory->makeConfig( 'unittest' );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( Config::class, $conf );
|
2016-05-01 19:29:11 +00:00
|
|
|
$this->assertSame( $conf, $factory->makeConfig( 'unittest' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 00:33:16 +00:00
|
|
|
public function testMakeConfigWithObject() {
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$conf = new HashConfig();
|
|
|
|
|
$factory->register( 'test', $conf );
|
|
|
|
|
$this->assertSame( $conf, $factory->makeConfig( 'test' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-01 19:29:11 +00:00
|
|
|
public function testMakeConfigFallback() {
|
|
|
|
|
$factory = new ConfigFactory();
|
|
|
|
|
$factory->register( '*', 'GlobalVarConfig::newInstance' );
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
$conf = $factory->makeConfig( 'unittest' );
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( Config::class, $conf );
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeConfigWithNoBuilders() {
|
|
|
|
|
$factory = new ConfigFactory();
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( ConfigException::class );
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
$factory->makeConfig( 'nobuilderregistered' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeConfigWithInvalidCallback() {
|
|
|
|
|
$factory = new ConfigFactory();
|
2021-02-07 13:10:36 +00:00
|
|
|
$factory->register( 'unittest', static function () {
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
return true; // Not a Config object
|
2014-07-19 21:12:10 +00:00
|
|
|
} );
|
2019-10-05 15:39:46 +00:00
|
|
|
$this->expectException( UnexpectedValueException::class );
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
$factory->makeConfig( 'unittest' );
|
|
|
|
|
}
|
2014-08-03 21:05:50 +00:00
|
|
|
|
|
|
|
|
public function testGetDefaultInstance() {
|
2016-05-01 19:29:11 +00:00
|
|
|
// NOTE: the global config factory returned here has been overwritten
|
|
|
|
|
// for operation in test mode. It may not reflect LocalSettings.
|
2022-01-12 20:13:39 +00:00
|
|
|
$factory = $this->getServiceContainer()->getConfigFactory();
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertInstanceOf( Config::class, $factory->makeConfig( 'main' ) );
|
2016-04-11 20:37:32 +00:00
|
|
|
}
|
2016-05-01 19:29:11 +00:00
|
|
|
|
Make abstract Config class truly implementation-agnostic
Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):
Config:
* Rather than returning Status objects, Config::set will now throw an exception
if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.
GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
abstract Config class is to abstract some notion of configuration data from
the particular way in which it is currently implemented (global variables).
So the abstract base class has no business dealing with variable name
prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
referring to the scope of the configuration value, but to the scope of the
variable name which provides it.
ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
This allows for implementations to construct the object with the parameters they want,
and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
ConfigFactory::getDefaultInstance()
In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
stores a name => callback. The name is to be what the Config instance is
registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
were improved.
Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
2014-05-10 08:19:00 +00:00
|
|
|
}
|