Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67514


Change subject: Improvements to ByPropertyIdArray and its test
......................................................................

Improvements to ByPropertyIdArray and its test

Change-Id: Iacadca5eb72325e07901aab6a422673733b6bf65
---
M DataModel/DataModel/ByPropertyIdArray.php
M DataModel/tests/phpunit/ByPropertyIdArrayTest.php
2 files changed, 43 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/14/67514/1

diff --git a/DataModel/DataModel/ByPropertyIdArray.php 
b/DataModel/DataModel/ByPropertyIdArray.php
index 4cd1ed1..7a98024 100644
--- a/DataModel/DataModel/ByPropertyIdArray.php
+++ b/DataModel/DataModel/ByPropertyIdArray.php
@@ -3,6 +3,8 @@
 namespace Wikibase;
 
 use MWException;
+use OutOfBoundsException;
+use RuntimeException;
 
 /**
  * Helper for doing indexed lookups of objects by property id.
@@ -75,11 +77,11 @@
         * @since 0.2
         *
         * @return integer[]
-        * @throws MWException
+        * @throws RuntimeException
         */
        public function getPropertyIds() {
                if ( $this->byId === null ) {
-                       throw new MWException( 'Index not build, call 
buildIndex first' );
+                       throw new RuntimeException( 'Index not build, call 
buildIndex first' );
                }
 
                return array_keys( $this->byId );
@@ -93,15 +95,15 @@
         * @param integer $propertyId
         *
         * @return object[]
-        * @throws MWException|OutOfBoundsException
+        * @throws RuntimeException|OutOfBoundsException
         */
        public function getByPropertyId( $propertyId ) {
                if ( $this->byId === null ) {
-                       throw new MWException( 'Index not build, call 
buildIndex first' );
+                       throw new RuntimeException( 'Index not build, call 
buildIndex first' );
                }
 
                if ( !( array_key_exists( $propertyId, $this->byId ) ) ) {
-                       throw new \OutOfBoundsException( 'Property id array key 
does not exist.' );
+                       throw new OutOfBoundsException( 'Property id array key 
does not exist.' );
                }
 
                return $this->byId[$propertyId];
diff --git a/DataModel/tests/phpunit/ByPropertyIdArrayTest.php 
b/DataModel/tests/phpunit/ByPropertyIdArrayTest.php
index 403b518..df82638 100644
--- a/DataModel/tests/phpunit/ByPropertyIdArrayTest.php
+++ b/DataModel/tests/phpunit/ByPropertyIdArrayTest.php
@@ -1,10 +1,20 @@
 <?php
 
 namespace Wikibase\Test;
-use Wikibase\ByPropertyIdArray, Wikibase\EntityId, Wikibase\Property, 
Wikibase\Snak;
+
+use DataValues\StringValue;
+use Wikibase\ByPropertyIdArray;
+use Wikibase\EntityId;
+use Wikibase\Property;
+use Wikibase\Snak;
+use Wikibase\Claim;
+use Wikibase\PropertyNoValueSnak;
+use Wikibase\PropertySomeValueSnak;
+use Wikibase\PropertyValueSnak;
+use Wikibase\Statement;
 
 /**
- * Tests for the Wikibase\ByPropertyIdArray class.
+ * @covers Wikibase\ByPropertyIdArray
  *
  * 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
@@ -40,25 +50,25 @@
                $lists = array();
 
                $snaks = array(
-                       new \Wikibase\PropertyNoValueSnak( new EntityId( 
Property::ENTITY_TYPE, 42 ) ),
-                       new \Wikibase\PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 42 ) ),
-                       new \Wikibase\PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 10 ) ),
-                       new \Wikibase\PropertyValueSnak( new EntityId( 
Property::ENTITY_TYPE, 10 ), new \DataValues\StringValue( 'ohi' ) ),
-                       new \Wikibase\PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 1 ) ),
+                       new PropertyNoValueSnak( new EntityId( 
Property::ENTITY_TYPE, 42 ) ),
+                       new PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 42 ) ),
+                       new PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 10 ) ),
+                       new PropertyValueSnak( new EntityId( 
Property::ENTITY_TYPE, 10 ), new StringValue( 'ohi' ) ),
+                       new PropertySomeValueSnak( new EntityId( 
Property::ENTITY_TYPE, 1 ) ),
                );
 
                $lists[] = $snaks;
 
                $lists[] = array_map(
-                       function( \Wikibase\Snak $snak ) {
-                               return new \Wikibase\Claim( $snak );
+                       function( Snak $snak ) {
+                               return new Claim( $snak );
                        },
                        $snaks
                );
 
                $lists[] = array_map(
-                       function( \Wikibase\Snak $snak ) {
-                               return new \Wikibase\Statement( $snak );
+                       function( Snak $snak ) {
+                               return new Statement( $snak );
                        },
                        $snaks
                );
@@ -135,4 +145,19 @@
 
                $indexedArray->getByPropertyId( 9000 );
        }
+
+       public function testNotBuildExceptionIsThrownForByPropertyId() {
+               $indexedArray = new ByPropertyIdArray();
+
+               $this->setExpectedException( 'RuntimeException' );
+               $indexedArray->getByPropertyId( 9000 );
+       }
+
+       public function testNotBuildExceptionIsThrownForGetPropertyIds() {
+               $indexedArray = new ByPropertyIdArray();
+
+               $this->setExpectedException( 'RuntimeException' );
+               $indexedArray->getPropertyIds();
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/67514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iacadca5eb72325e07901aab6a422673733b6bf65
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

Reply via email to