diff --git a/includes/SkinOptions.php b/includes/SkinOptions.php index 4544d26..780736c 100644 --- a/includes/SkinOptions.php +++ b/includes/SkinOptions.php @@ -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 ); } diff --git a/tests/phpunit/unit/SkinOptionsTest.php b/tests/phpunit/unit/SkinOptionsTest.php index 491c500..c29cd84 100644 --- a/tests/phpunit/unit/SkinOptionsTest.php +++ b/tests/phpunit/unit/SkinOptionsTest.php @@ -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 + ] ); + } }