Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/67516
Change subject: Improvements to MapValueHasher and its test ...................................................................... Improvements to MapValueHasher and its test Change-Id: I9b74c61ecc628891c3457821188dc0fd4afc504d --- M DataModel/DataModel/MapValueHasher.php M DataModel/tests/phpunit/MapValueHasherTest.php 2 files changed, 40 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/16/67516/1 diff --git a/DataModel/DataModel/MapValueHasher.php b/DataModel/DataModel/MapValueHasher.php index 151ece8..4da34c2 100644 --- a/DataModel/DataModel/MapValueHasher.php +++ b/DataModel/DataModel/MapValueHasher.php @@ -2,9 +2,9 @@ namespace Wikibase; +use InvalidArgumentException; use Traversable; use Hashable; -use MWException; /** * Generates hashes for associative arrays based on the values of their elements. @@ -27,7 +27,7 @@ * @since 0.1 * * @file - * @ingroup WikibaseLib + * @ingroup WikibaseDataModel * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -60,11 +60,11 @@ * @param Traversable|Hashable[] $map * * @return string - * @throws MWException + * @throws InvalidArgumentException */ public function hash( $map ) { if ( !is_array( $map ) && !( $map instanceof Traversable ) ) { - throw new MWException( 'MapHasher::hash only accepts Traversable objects (including arrays)' ); + throw new InvalidArgumentException( 'MapHasher::hash only accepts Traversable objects (including arrays)' ); } $hashes = array(); diff --git a/DataModel/tests/phpunit/MapValueHasherTest.php b/DataModel/tests/phpunit/MapValueHasherTest.php index 287c2c0..365b171 100644 --- a/DataModel/tests/phpunit/MapValueHasherTest.php +++ b/DataModel/tests/phpunit/MapValueHasherTest.php @@ -1,26 +1,45 @@ <?php namespace Wikibase\Test; + +use Wikibase\EntityId; use Wikibase\MapValueHasher; +use Wikibase\Property; +use Wikibase\PropertyNoValueSnak; /** - * Tests for the Wikibase\MapValueHasher class. + * @covers Wikibase\MapValueHasher + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html * * @file * @since 0.1 * - * @ingroup WikibaseLib + * @ingroup WikibaseDataModel * @ingroup Test * * @group Wikibase - * @group WikibaseLib + * @group WikibaseDataModel * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > */ class MapValueHasherTest extends \PHPUnit_Framework_TestCase { - public function testCanConstructor() { + public function testCanConstruct() { new MapValueHasher( true ); $this->assertTrue( true ); } @@ -29,10 +48,10 @@ $hasher = new MapValueHasher(); $map0 = array( - 'foo' => new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 1 ) ), - 'bar' => new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 2 ) ), - 42 => new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 42 ) ), - new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 9001 ) ), + 'foo' => new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 1 ) ), + 'bar' => new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 2 ) ), + 42 => new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 42 ) ), + new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 9001 ) ), ); $hash = $hasher->hash( $map0 ); @@ -52,9 +71,16 @@ $this->assertNotEquals( $hash, $hasher->hash( $map2 ) ); $map3 = $map0; - $map3['foo'] = new \Wikibase\PropertyNoValueSnak( new \Wikibase\EntityId( \Wikibase\Property::ENTITY_TYPE, 5 ) ); + $map3['foo'] = new PropertyNoValueSnak( new EntityId( Property::ENTITY_TYPE, 5 ) ); $this->assertNotEquals( $hash, $hasher->hash( $map3 ) ); } -} \ No newline at end of file + public function testHashThrowsExceptionOnInvalidArgument() { + $hasher = new MapValueHasher(); + + $this->setExpectedException( 'InvalidArgumentException' ); + $hasher->hash( null ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/67516 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b74c61ecc628891c3457821188dc0fd4afc504d 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
