X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fregistration%2FExtensionRegistry.php;h=e3df499987552c764b670b961df2c4dbac981528;hb=dbe54b46e6761575112e0cb0aaf7e1569366da9c;hp=3138b37a04731c41bfe99aed3a05ed7ffff37432;hpb=1dee28cb5f1efd6d9e14d6cc1d0c73c3f69269b4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 3138b37a04..e3df499987 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -1,6 +1,7 @@ attributes[$name] ?? []; + return $this->testAttributes[$name] ?? + $this->attributes[$name] ?? []; + } + + /** + * Force override the value of an attribute during tests + * + * @param string $name Name of attribute to override + * @param array $value Value to set + * @return ScopedCallback to reset + * @since 1.33 + */ + public function setAttributeForTest( $name, array $value ) { + // @codeCoverageIgnoreStart + if ( !defined( 'MW_PHPUNIT_TEST' ) ) { + throw new RuntimeException( __METHOD__ . ' can only be used in tests' ); + } + // @codeCoverageIgnoreEnd + if ( isset( $this->testAttributes[$name] ) ) { + throw new Exception( "The attribute '$name' has already been overridden" ); + } + $this->testAttributes[$name] = $value; + return new ScopedCallback( function () use ( $name ) { + unset( $this->testAttributes[$name] ); + } ); } /**