Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64497
Change subject: Improvements to SettingsArray and its tests
......................................................................
Improvements to SettingsArray and its tests
Change-Id: Icc39b332a399ec09b3f35cead319d9be1595aeee
---
M lib/includes/SettingsArray.php
M lib/tests/phpunit/SettingsArrayTest.php
2 files changed, 58 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/97/64497/1
diff --git a/lib/includes/SettingsArray.php b/lib/includes/SettingsArray.php
index 4173ec8..ab78d9b 100644
--- a/lib/includes/SettingsArray.php
+++ b/lib/includes/SettingsArray.php
@@ -1,7 +1,8 @@
<?php
namespace Wikibase;
-use MWException;
+
+use OutOfBoundsException;
/**
* Class representing a collection of settings.
@@ -33,16 +34,16 @@
/**
* Gets the value of the specified setting.
*
- * @since 0.14
+ * @since 0.1
*
* @param string $settingName
*
- * @throws MWException
+ * @throws OutOfBoundsException
* @return mixed
*/
public function getSetting( $settingName ) {
if ( !$this->offsetExists( $settingName ) ) {
- throw new MWException( 'Attempt to get non-existing
setting "' . $settingName . '"' );
+ throw new OutOfBoundsException( 'Attempt to get
non-existing setting "' . $settingName . '"' );
}
return $this[$settingName];
diff --git a/lib/tests/phpunit/SettingsArrayTest.php
b/lib/tests/phpunit/SettingsArrayTest.php
index 6f8b129..a233c5a 100644
--- a/lib/tests/phpunit/SettingsArrayTest.php
+++ b/lib/tests/phpunit/SettingsArrayTest.php
@@ -1,10 +1,11 @@
<?php
namespace Wikibase\Lib\Test;
+
use Wikibase\SettingsArray;
/**
- * Tests for the SettingsArray class.
+ * @covers Wikibase\SettingsArray
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,48 +29,70 @@
*
* @group Wikibase
* @group WikibaseLib
+ * @group SettingsArrayTest
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class SettingsArrayTest extends \MediaWikiTestCase {
+class SettingsArrayTest extends \PHPUnit_Framework_TestCase {
- public function settingArrayProvider() {
- $settingArrays = array();
+ /**
+ * @dataProvider settingProvider
+ */
+ public function testGetKnownSetting( array $settings ) {
+ $settingsArray = new SettingsArray( $settings );
- $settingArrays[] = new SettingsArray();
+ foreach ( $settingsArray as $settingName => $settingValue ) {
+ $this->assertEquals( $settingValue,
$settingsArray->getSetting( $settingName ) );
+ }
- return $this->arrayWrap( $settingArrays );
+ $this->assertSameSize( $settings, $settingsArray );
+ }
+
+ public function settingProvider() {
+ $argLists = array();
+
+ $argLists[] = array( array() );
+
+ $argLists[] = array( array(
+ 'foo' => 'bar'
+ ) );
+
+ $argLists[] = array( array(
+ 'foo' => 'bar',
+ 'baz' => 'bah',
+ ) );
+
+ $argLists[] = array( array(
+ 'foo' => 'bar',
+ 'baz' => 'bah',
+ 'blah' => 'bah',
+ 'nyan' => 1337,
+ 'onoez' => array( 1, 2, 3 ),
+ 'spam' => false,
+ 'hax' => null,
+ ) );
+
+ return $argLists;
}
/**
- * @dataProvider settingArrayProvider
- *
- * @param SettingsArray $settings
+ * @dataProvider settingProvider
*/
- public function testGetSetting( SettingsArray $settings ) {
- foreach ( $settings as $settingName => $settingValue ) {
- $this->assertEquals( $settingValue,
$settings->getSetting( $settingName ) );
- }
+ public function testGetUnknownSetting( array $settings ) {
+ $settingsArray = new SettingsArray( $settings );
- $unknownSettings = array( 'dzgtxdfgtdsrxstds4ryt',
'sadftsrftszy' );
+ $this->setExpectedException( 'OutOfBoundsException' );
- foreach ( $unknownSettings as $unknownSetting ) {
- $this->assertException(
- function() use ( $settings, $unknownSetting ) {
- $settings->getSetting( $unknownSetting
);
- },
- 'MWException'
- );
- }
+ $settingsArray->getSetting( 'NyanData ALL the way across the
sky' );
}
/**
- * @dataProvider settingArrayProvider
- *
- * @param SettingsArray $settings
+ * @dataProvider settingProvider
*/
- public function testHasSetting( SettingsArray $settings ) {
+ public function testHasSetting( array $settings ) {
+ $settings = new SettingsArray( $settings );
+
foreach ( array_keys( iterator_to_array( $settings ) ) as
$settingName ) {
$this->assertTrue( $settings->hasSetting( $settingName
) );
}
@@ -78,11 +101,11 @@
}
/**
- * @dataProvider settingArrayProvider
- *
- * @param SettingsArray $settings
+ * @dataProvider settingProvider
*/
- public function testSetSetting( SettingsArray $settings ) {
+ public function testSetSetting( array $settings ) {
+ $settings = new SettingsArray( $settings );
+
foreach ( $settings as $settingName => $settingValue ) {
$settings->setSetting( $settingName, $settingValue );
$this->assertEquals( $settingValue,
$settings->getSetting( $settingName ) );
--
To view, visit https://gerrit.wikimedia.org/r/64497
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icc39b332a399ec09b3f35cead319d9be1595aeee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits