aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/structure/SettingsTest.php
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2022-01-26 11:42:59 -0800
committerDaniel Kinzler <dkinzler@wikimedia.org>2022-02-03 13:27:47 +0000
commitd54e3d216c58480a8fae222de96da377daf9d907 (patch)
tree48ca9fd000aed430b5bf2b5502bc3697c46da017 /tests/phpunit/structure/SettingsTest.php
parente8552f82a04a9bdfc7d1d322fe65591345df9d5e (diff)
downloadmediawikicore-d54e3d216c58480a8fae222de96da377daf9d907.tar.gz
mediawikicore-d54e3d216c58480a8fae222de96da377daf9d907.zip
Add pre-generator for config-schema.php
Bug: T300129 Change-Id: Ib2620993114af5a659bda60dc45b6fb3bed657b0
Diffstat (limited to 'tests/phpunit/structure/SettingsTest.php')
-rw-r--r--tests/phpunit/structure/SettingsTest.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/phpunit/structure/SettingsTest.php b/tests/phpunit/structure/SettingsTest.php
index b1d1a6af6e8c..263ca88f02ed 100644
--- a/tests/phpunit/structure/SettingsTest.php
+++ b/tests/phpunit/structure/SettingsTest.php
@@ -6,6 +6,10 @@ use ExtensionRegistry;
use MediaWiki\Settings\Config\ArrayConfigBuilder;
use MediaWiki\Settings\Config\PhpIniSink;
use MediaWiki\Settings\SettingsBuilder;
+use MediaWiki\Settings\Source\FileSource;
+use MediaWiki\Settings\Source\PhpSettingsSource;
+use MediaWiki\Settings\Source\SettingsSource;
+use MediaWiki\Shell\Shell;
use MediaWikiIntegrationTestCase;
/**
@@ -53,11 +57,39 @@ class SettingsTest extends MediaWikiIntegrationTestCase {
$this->assertTrue( $result->isGood(), $result->__toString() );
}
+ public function testConfigSchemaPhpGenerated() {
+ $schemaGenerator = Shell::makeScriptCommand(
+ __DIR__ . '/../../../maintenance/generateConfigSchema.php',
+ [ '--output', 'php://stdout' ]
+ );
+
+ $result = $schemaGenerator->execute();
+ $this->assertSame( 0, $result->getExitCode(), 'Config doc generation must finish successfully' );
+ $this->assertSame( '', $result->getStderr(), 'Config doc generation must not have errors' );
+
+ $oldGeneratedSchema = file(
+ __DIR__ . '/../../../includes/config-schema.php',
+ FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
+ );
+
+ $this->assertArrayEquals(
+ $oldGeneratedSchema,
+ preg_split( "/\\n/", $result->getStdout(), -1, PREG_SPLIT_NO_EMPTY ),
+ 'Configuration schema was changed. Rerun maintenance/generateConfigSchema.php script!'
+ );
+ }
+
+ public function provideDefaultSettingsConsistency() {
+ yield 'YAML' => [ new FileSource( 'includes/config-schema.yaml' ) ];
+ yield 'PHP' => [ new PhpSettingsSource( 'includes/config-schema.php' ) ];
+ }
+
/**
* Check that the result of loading config-schema.yaml is the same as DefaultSettings.php
* This test can be removed when DefaultSettings.php is removed.
+ * @dataProvider provideDefaultSettingsConsistency
*/
- public function testDefaultSettingsConsistency() {
+ public function testDefaultSettingsConsistency( SettingsSource $source ) {
$defaultSettingsProps = ( static function () {
$IP = 'PLACEHOLDER_IP!';
require __DIR__ . '/../../../includes/DefaultSettings.php';
@@ -78,7 +110,7 @@ class SettingsTest extends MediaWikiIntegrationTestCase {
$configBuilder,
$this->createNoOpMock( PhpIniSink::class )
);
- $settingsBuilder->loadFile( 'includes/config-schema.yaml' );
+ $settingsBuilder->load( $source );
$settingsBuilder->apply();
foreach ( $defaultSettingsProps as $key => $value ) {