Hygiene: SkinOptions should validate options
Changes: - when trying to set unknown option, throw exception - added unit tests Bug: T221012 Change-Id: I0d1a43fb5a7179b8e9cd578e3e33bab12ddfd61c
This commit is contained in:
parent
3dd8ce4822
commit
9ece509c99
|
@ -68,6 +68,11 @@ final class SkinOptions {
|
|||
* @param array $options
|
||||
*/
|
||||
public function setMultiple( array $options ) {
|
||||
foreach ( $options as $option => $value ) {
|
||||
if ( !array_key_exists( $option, $this->skinOptions ) ) {
|
||||
throw new \OutOfBoundsException( "SkinOption $option is not defined" );
|
||||
}
|
||||
}
|
||||
$this->skinOptions = array_merge( $this->skinOptions, $options );
|
||||
}
|
||||
|
||||
|
|
|
@ -46,4 +46,24 @@ class SkinOptionsTest extends \MediaWikiUnitTestCase {
|
|||
] );
|
||||
$this->assertFalse( $options->hasSkinOptions() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testGettingUnknownKeyShouldThrowException() {
|
||||
$options = new SkinOptions();
|
||||
$options->get( 'non_existing_key' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
public function testSettingUnknownKeyShouldThrowException() {
|
||||
$options = new SkinOptions();
|
||||
$options->setMultiple( [
|
||||
'non_existing_key' => 1
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue